I tried to encrypt a data using 16bit key using ecb mode for rinjndael_128 cipher. the encrption was successful and i can also succesfully decrypt the encrypted data. But the problem is, the mcrypt_encrypt function returns the garbled character string. I want to see this result in hex format.
while Im using the online tool for the same data getting this hex value as result bd61ce515890e2e3fb5e404bbe886cc2
code
$key = pack('H*', "07070609070306050601070007000700");
$plaintext = "2dfb0998b2f76f35f5b08972b57cfbfc";
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaintext, MCRYPT_MODE_ECB);
$ciphertext_base64 = base64_encode($ciphertext);
echo "encrypted - text: ".$ciphertext . "<br>";
echo "encrypted base 64 encoded - text: ".$ciphertext_base64 . "<br>";
$ciphertext_dec = base64_decode($ciphertext_base64);
$plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key,$ciphertext_dec, MCRYPT_MODE_ECB);
echo "decrypted data - text: ".$plaintext_dec . "<br>";
Result:
before encryption - text: 2dfb0998b2f76f35f5b08972b57cfbfc
encrypted - text: (MÓx‹ÓåBÖ i½4²5žNUXÃè/Óë£@ö
encrypted base 64 encoded - text: KE3TeIsa0+VC1g1pCL00sjWeTlVYw+iNgS/TEOujQPY=
decrypted data - text: 2dfb0998b2f76f35f5b08972b57cfbfc*