MCrypt rijndael-128 to OpenSSL aes-128-ecb conversion

Here is what worked for me: <?php $str=”Content”; if (strlen($str) % 16) { $str = str_pad($str, strlen($str) + 16 – strlen($str) % 16, “\0”); } $key = ‘KEY’; if (strlen($key) % 16) { $key = str_pad($key, strlen($key) + 16 – strlen($key) % 16, “\0”); } $res1 = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB); echo strToHex($res1) . ‘ … Read more

mcrypt_encrypt to openssl_encrypt, and OPENSSL_ZERO_PADDING problems

mcrypt_encrypt zero-pads input data if it’s not a multiple of the blocksize. This leads to ambiguous results if the data itself has trailing zeroes. Apparently OpenSSL doesn’t allow you to use zero padding in this case, which explains the false return value. You can circumvent this by adding the padding manually. $message = “Lorem ipsum”; … Read more