I'm trying to make a C program and openssl CLI generate consistent output for AES encryption.
For encryption, I'm using this C and OpenSSL EVP example: https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption#Encrypting_the_message
And it is invoked as follows:
....
#include <openssl/conf.h>
#include <openssl/evp.h>
#include <openssl/err.h>
....
int main()
{
char ciphertext[1024];
static char *enckey = (char *) "7c07f68ea8494b2f8b9fea297119350d78708afa69c1c7600000000000000000";
static char *iv = (char *)"FEDCBA09876543210000000000000000";
size_t* output_length;
ssize_t crypto_length = encrypt("test", 4, enckey, iv, ciphertext);
printf("%s", base64_encode(ciphertext, crypto_length, output_length) );
}
For OpenSSL CLI I'm using:
openssl enc -aes-256-cbc -e -a -A -in input.dat \
-K 7c07f68ea8494b2f8b9fea297119350d78708afa69c1c7600000000000000000 -iv FEDCBA09876543210000000000000000
Identical key, IV, plaintext (the input.dat has just "test" inside (without quotes)), identical mode - AES-256-CBC.
And yet, I get two different outputs:
- EVP+C:
HBy5KT15kp+dLFuBNU15rw==
- CLI:
zcTjiVTkZI8XSpDbc0HvRA==
(I get the same with a Java program with the same parameters)
Any idea why these would generate different outputs, and therefore the EVP output can't be decrypted in CLI.
encrypt()
method.