几个网站上有一个 mcrypt 片段:
https://stackoverflow.com/a/11538728/408872
http://www.techbees.org/best-way-to-use-php-to-encrypt-and-decrypt/
$key = 'password to (en/de)crypt';
$string = ' string to be encrypted '; // note the spaces
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
echo 'Encrypted:' . "\n";
var_dump($encrypted);
echo "\n";
echo 'Decrypted:' . "\n";
var_dump($decrypted); // spaces are preserved
任何人都知道为什么在 $string 上引入了额外的空格?