I am new to encryption. I want to encode a string with AES 128bit encryption. I can do this in PHP:
$key = 'Hello';
$plain = 'Hello Hello Hello Hello';
$cipher = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plain, MCRYPT_MODE_CBC);
echo base64_encode($cipher);
This outputs:
bzXdTNochlsQwpR9hzSSS6ihG+MYIZIDZZlF85pIXlQ=
I tried the same with openssl command line:
openssl enc -aes-128-cbc -a -nosalt -in plain.txt -out encrypted.enc -pass pass:Hello
And the string saved in encrypted.enc is:
5apwiN8MdAuJ9nEW82XMyR0H3VKpI/vWc7xV2iVjCTE=
Why is it different?
The reason why I am trying to get the same output with both PHP and command line openssl is because I will have two separate web services communicating together. One service will have PHP available so I can use that but the other one will not be using PHP so I will probably have to use openssl in command line.
-pass pass:Hellodoes not look like to set the same password. And I think good encryption does not look always the same even the plain and the password are the same. It is more important if you can decrypt what you have crypted with the other one and vice-versa.