To replace mcrypt with openssl I have the following task:
The actual code for encryption and decryption is something like
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,$plaintext, MCRYPT_MODE_CBC, $iv);
and
$result_decrypt = mcrypt_decrypt(
'rijndael-128',
$key,
$ciphertext,
'cbc',
$iv
);
Works fine, all things are good. Now I want to decrypt the $ciphertext with openssl, I look at MCrypt rijndael-128 to OpenSSL aes-128-ecb conversion and try
function decrypt_openssl_rijndael($value, $unserialize = true, $salt)
{
if (!extension_loaded('openssl')) {
throw new \RuntimeException(
'SSL extension is not available.'
);
}
$decrypted = openssl_decrypt($value, 'aes-128-ecb', $salt, OPENSSL_RAW_DATA );
if ($unserialize) {
return unserialize($decrypted);
} else {
return $decrypted;
}
}
I test several options, but I got no properly decrypted string. I suppose I just missed one little thing, so if someone has an idea?
Regards Thomas