Sample of decrypting AES cbc with openssl
vscmaster opened this issue · comments
Helle encrypt team,
We are trying to encrypt with the encrypt plugin and decrypt with openssl (Mac) and stuck for 2 days.
Could you give some more details about params what encrypt plugin uses?
Or please give us some real sample how to decrypt with openssl?
Here is our impl:
const keyS = 'my 32 length key................';
const ivS = 'my 32 length key Block................';
final keyUtf8 = utf8.encode(keyS);
final ivUtf8 = utf8.encode(ivS);
final keySHA = sha256.convert(keyUtf8).toString().substring(0, 32);
final ivSHA = sha256.convert(ivUtf8).toString().substring(0, 16);
final iv = IV.fromUtf8(ivSHA);
final key = Key.fromUtf8(keySHA);
final encrypter = Encrypter(AES(key, mode: AESMode.cbc));
log.d('key: $keySHA, iv: $ivSHA');
return encrypter.encrypt(data, iv: iv).base64;
Then base64 stores to a file.
And openssl command to decrypt the file:
openssl enc -aes-256-cbc -nosalt -d -a -in PumbDigitalLogs.enc -out file.txt -K 5d6b9ce40778d9915472d725cc3dbe1f -iv 6c19a6ccd698885a
Here key and IV we've taken above.
key: 5d6b9ce40778d9915472d725cc3dbe1f
IV: 6c19a6ccd698885a
The error is next:
bad decrypt
8463212032:error:06FFF06D:digital envelope routines:CRYPTO_internal:wrong final block length:/AppleInternal/Library/BuildRoots/c2cb9645-dafc-11ed-aa26-6ec1e3b3f7b3/Library/Caches/com.apple.xbs/Sources/libressl/libressl-3.3/crypto/evp/evp_enc.c:540:
Besides, we found online decryptor which is decrypts well with these key/VI. https://www.javainuse.com/aesgenerator
Thank you