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
1c1,2
< 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
./example_encrypt_decrypt_cbc
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.