2
votes

Im trying to encrypt/decrypt aes a string and I keep getting an error when i decrypt it.

set OPENSSL=C:\Projects\WinTools\Tools\OpenSSL\x86\bin
set Key=748FBA160C30A2624859A44A1830C061434C76E3278AFB75330C8CA2CF1F5184
set IV=84DB32005B226D7F9964B758C9157538
set Salt=96F697CA35CED67A

I encrypt as follows:

echo "Test is test" | %OPENSSL%\openssl enc -base64 -e -aes-256-cbc -S %Salt% -K %Key% -iv %IV%

Decrypting it:

echo "7nO8yVKleLvbSneIi7qr82oSuiwRtnt5Iqqoynidl90=" | %OPENSSL%\openssl enc -base64 -d -aes-256-cbc -S %Salt% -K %Key% -iv %IV%

The error i get when decrypting is:

WARNING: can't open config file: /usr/local/ssl/openssl.cnf bad decrypt 4124:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:.\crypto\evp\evp_enc.c:532:

1

1 Answers

3
votes

Update: I figured out the problem. I was enclosing the encrypted data between the double quotes. When I removed it and run it like this:

echo 7nO8yVKleLvbSneIi7qr82oSuiwRtnt5Iqqoynidl90= | %OPENSSL%\openssl enc -base64 -d -aes-256-cbc -S %Salt% -salt -K %Key% -iv %IV% 

It decrypts perfectly