Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does two different implementation of Aes has different cipher text?

i am using a library 1 Aes algorithm implementation now i want to change it to another implementation of library 2 its working fine but the thing is its giving me diff encrypted data form library 1 , is it possible for Aes implementation with ECB mode 128 bit with same key and plain text but differs only in cipher text(encrypted data) for 2 different implementation?

i found one more thing that is if i pass input byte which is less then 16 byte then the encrypted data of both library is getting matched but again in library1 the decryption is perfect but in library2 its showing encrypt and decrypt are same(not exactly decrypting to original text) what would be the problem?

like image 393
sukumar Avatar asked Nov 27 '25 15:11

sukumar


1 Answers

Given your comment that strings less than 16 bytes lead to the same output, along with your use of ECB (which you should never use), my suspicion is that one of your libraries does not actually use ECB, and instead defaults to CBC (which is a much better default) and that you are passing a NULL IV to CBC. If my theory is correct, then you should expect the first 16 bytes to always be the same, and differences to begin after that point.

The best solution to this is to convert all of your code from ECB (which is deeply broken in all but some very rare situations) to CBC or just about any other mode you can find. CBC is the most common, and you will need to pass it an randomly generated IV.

If switching modes is impossible, I would investigate your second library and determine how to set it into ECB mode, which it probably is not currently in. Whoever is relying on your encryption should be warned that using ECB mode leaks significant information about the plaintext. Sometimes it's barely encrypted at all. See the entry at Wikipedia for a nice visual example of how bad it really is. This isn't some theoretical attack. It's really, really broken.

like image 200
Rob Napier Avatar answered Dec 01 '25 08:12

Rob Napier