I need to make a simple very basic encryption with AES 128 ECB mode.
The idea is to generate a cryptogram, code it in base64 and then decipher that text from a web service in php to process its content. Later we will increase the robustness of the encryption with a 256 key and CBC mode.
The problem is that the encrypted text generated from the openssl tool (installed by default in MacOX) generates a completely different result than the one generated by the openssl_encrypt function in php 7.
echo -n 'Sergio Sánchez' | openssl12n enc -aes-128-ecb -a
echo -n 'Sergio Sánchez' | openssl12n enc -aes-128-ecb -nosalt -a
echo base64_encode(openssl_encrypt('Sergio Sánchez', 'AES-128-ECB', 'password', OPENSSL_RAW_DATA));
How can I generate a compatible cryptogram between both tools?
I understand that in the case of the openssl tool the password must be specified in hexadecimal with the -K option
echo -n 'Sergio Sánchez' | openssl12n enc -aes-256-ecb -K 6f7850743453795a7558436b32435349 -a
The generated result will be the following:
In the case of php I specify the key in text:
echo openssl_encrypt('Sergio Sánchez', 'AES-128-ECB', 'oxPt4SyZuXCk2CSI');
The generated result will be the following