我如何识别双AES加密密文
我错误地将我的一些值在数据库中进行了两次加密。 有没有办法识别双重加密密文。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以做到这一点,两者都是高确定性,但有缺点。
首先,如果您不给出格式良好的键 / 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 containSalted__
in ASCII (followed by the salt and then the AES-CBC / PKCS#7 ciphertext). As your plaintext is unlikely to start withSalted__
this should be enough of a distinguisher. So your decrypt routine could run in a loop until theSalted__
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.