例子:
$data = "Test Data\x00\x00";
echo strlen($data);
$key = "mykey";
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, MD5($key, true), $data, MCRYPT_MODE_ECB);
echo strlen($encrypted);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, MD5($key, true), $encrypted, MCRYPT_MODE_ECB);
echo strlen($decrypted);
$newData = rtrim($decrypted,"\x00");
echo strlen($newData);
输出:
11
16
16
9 <-- I want 11 here
那么,有什么方法可以解密在加密之前可能已经填充空的数据,并取回正确的长度数据?