我如何识别双AES加密密文

发布于 2025-02-11 06:08:20 字数 224 浏览 2 评论 0原文

我错误地将我的一些值在数据库中进行了两次加密。 有没有办法识别双重加密密文。

    var ciphertext = cryptoJS.AES.encrypt(plainText, secretKey).toString();
    var ciphertext2 = cryptoJS.AES.encrypt(ciphertext, secretKey).toString();

I mistakenly encrypted some of my values in the db twice.
Is there a way to identify double encrypted ciphertext.

    var ciphertext = cryptoJS.AES.encrypt(plainText, secretKey).toString();
    var ciphertext2 = cryptoJS.AES.encrypt(ciphertext, secretKey).toString();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睫毛上残留的泪 2025-02-18 06:08:20

有两种方法可以做到这一点,两者都是高确定性,但有缺点。

首先,如果您不给出格式良好的键 / IV,则加密cryptojs将使用openssl键推导机制来推导键和iv。如果您使用toString(),它将串起结果。当然,这会增加一些开销,因此,如果您知道消息的原始大小,那么您可以尝试通过增加大小来检测双重加密即可。

其次,您可以解密一次,然后查找toString生成的格式。这是一个基本的64字符串,解码后应在ASCII中包含盐> __ < / code>(随后是盐,然后是AES-CBC / PKCS#7 Ciphertext)。由于您的明文不太可能以盐度__开始,这应该足够了。因此,您的解密例程可以在循环中运行,直到Salted __ String再也没有找到。

否则:AES加密的密文已完全随机化,因此您看不到任何查看密文本身的内容。但是,在这种情况下,密文是的专有协议的一部分,它打开了一些可能的可能性。

There are two ways to do this, and both are high certainty but have drawbacks.

First of all, if you don't give an well formatted key / IV then CryptoJS will use an OpenSSL key derivation mechanism to derive the key and IV. If you use toString() it will then stringify the result. This of course adds some overhead, so if you know the original size of the message then you can simply try and detect double encryption by the increase of the size.

Second, you can decrypt once, and then look for the format that toString generates. This is a base 64 string which, after decoding, should contain Salted__ in ASCII (followed by the salt and then the AES-CBC / PKCS#7 ciphertext). As your plaintext is unlikely to start with Salted__ this should be enough of a distinguisher. So your decrypt routine could run in a loop until the Salted__ string isn't found anymore.

Otherwise: AES encrypted ciphertext is fully randomized, so you cannot see anything looking at the ciphertext itself. In this case however, the ciphertext is part of a proprietary protocol, which opens up some possiblities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文