openssl AES-128-CBC can be decrypted with a new IV different than the IV from encryption.

It seems that IV does not change the cipher too much as long as they share the same key.

I have an example using K=k1 and iv= iv1 to encrypt a file A to B, then I use k=k1 iv=iv2 to decrypt cipher file B into clear text C. Surprisingly, the difference between A and C is not much

k1  = 37424344454647483132333435363738
iv1 = 394832344b697d302524792138325e23
iv2 = 61626364242525262331323334374b4c

The following are commands

$openssl aes-128-cbc -K '37424344454647483132333435363738' -iv '394832344b697d302524792138325e23' -out test -in commands 

$openssl aes-128-cbc -d -K '37424344454647483132333435363738' -iv '394832344b697d302524792138325e23' -in test -out clearText

$diff commands clearText 

The above command produces nothing as these two files are identical as expected.

Let us decrypt the cipher file with iv2.

$openssl aes-128-cbc -d -K '37424344454647483132333435363738' -iv '61626364242525262331323334374b4c' -in test -out clearText2

$diff commands  clearText2
< File starts here 
> C=5O?,wta82d`g

One would expect the file clearText2 either not readable or much different than the original plain text file "commands". That is a big surprise to me. Is that a vulnerability for openssl or I did something wrong?

You can create your own plain text file as input and result would be similar

The plain text file commands is as follows. Text file start with "File start here" - included, ends with "File ends here", and no space after that.

File starts here

$ openssl aes-128-cbc -K '41424344454647483132333435363738' -iv '61626364656667683132333435363738' -in plainFile -out out

decrypt by openssl
 $ openssl aes-128-cbc -d -K '41424344454647483132333435363738' -iv '61626364656667683132333435363738' -in cipherFile -out out

If the above does not work, add -nopad.

$ openssl aes-128-cbc -d -nopad -K '41424344454647483132333435363738' -iv '61626364656667683132333435363738' -in cipherFile -out out

iv = baXde$gh87&456%8

openssl aes-128-cbc -d -K '41424344454647483132333435363738' -iv '62615864652467683837263435362538' -in cipherFile -out  out

openssl aes-128-cbc  -d -K '41424344454647483132333435363738' -iv '394031324b697d302524792137325e23' -in cipherFile -out  out

openssl aes-128-cbc  -d -K '41424344454647483132333435363738' -iv '394031324b697d302524792137325e30' -in cipherFile -out  out

File ends here.

  • 2
    That's correct. WIth AES-CBC decryption, the IV is used only in the computation of the first block of decrypted ciphertext. See security.stackexchange.com/questions/217862/… for some interesting reading on this subject, and the impacts that this can have if the IV is not authenticated.
    – mti2935
    May 24, 2023 at 16:54

2 Answers 2


When decrypting AES ciphertext in CBC mode, the given initialization vector is only used to produce the plaintext for the first 16-byte block, as you can see in this diagram. For the subsequent blocks, the IV isn't needed at all.

Of course the IV used during encryption affects all ciphertext blocks. For different IVs, you'll get entirely different ciphertexts. However, when you decrypt, the IV used during encryption is “implied” through the ciphertext blocks, so you don't have to know it except for the first block.


That is correct. CBC is block based cipher which means it encrypts block by block. in CBC when You are encrypting each block it depends on ciphertext of previous block. since first block does not have a previous block, IV is used to have something to start encrypting first block of message.

now for decrypting You do reverse. You need IV for decrypting the first block and other blocks use previous block ciphertext(like encryption). Since your ciphertext is what it was during encryption, then all blocks but the first one will be decrypted correct.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .