In AES, For The Same Plaintext, Will We Always Get Same Ciphertext (for the same IV and Key)?
You will perhaps know that in ECB (Electronic Code Book) mode in AES, you will always get the same ciphertext for the same key. As this is a block cipher, the padding will change the end characters, but as long as we have 16 bytes then the first block will be the same. But what about the modes that use an IV? Well, let’s look at a stream cipher mode: GCM, and see what happens when we use the same key and the same IV.
So we will create the following Golang cod.
In this case, we just convert a password into an encryption key, and then just set an IV to all zeros, along with the same salt used with the key generation. If we try “Testing 123” and a password of “qwerty123”, we get :
If we use the same encryption key and IV, and encrypt “Testing 1234”, we get :
If we use the same encryption key and IV, and encrypt “Testing 12354”, we get :
And so we see “The following is the Golang code :
If we try “Testing 123” and a password of “qwerty123” :
If we use the same encryption key and IV, and encrypt “Testing 1234”, we get :
If we use the same encryption key and IV, and encrypt “Testing 12354”, we get :
And so we see “80f8087e75d6875d56198” for each of the cipher, and basically that maps to “Testing 123”. The ciphering of “4” is thus: “ac”, and “5” is “fa”.
And so we can see that we get the same out for our ciphering, for the same key and the same IV for each of the modes.