<?php
$key = hex2bin('000102030405060708090a0b0c0d0e0f');
$message = hex2bin('5061726101676f6e000300');
$iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $message, MCRYPT_MODE_CBC, $iv);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $encrypted, MCRYPT_MODE_CBC, $iv);
// This should still be padded:
var_dump(bin2hex($decrypted));
// Let's strip off the padding:
$stripped = rtrim($decrypted, "\0");
var_dump(bin2hex($stripped));
// Does this equal the original message?
var_dump($stripped === $message);
preferences:
32.56 ms | 407 KiB | 5 Q