【发布时间】:2011-07-05 04:51:54
【问题描述】:
我正在使用我制作的这个函数来加密数据:
function encryptCredential($data) {
$key = '9cqkTFHOfOmKn8kt&NSlIK*XMRWWx*tNY$azRdEvm2to*AQOll%8tP18g35H!zNg9l85pgnww$&q6y@1WrWZhKhx&23acq^*FWf*xdnmI%7aWwM6JQLm%tzYG^*8PIh1zD@D5QKa98Gg';
$encryptedData = mcrypt_cbc(MCRYPT_TripleDES, substr($key,0,32), pad($data), MCRYPT_ENCRYPT, substr($key,32,16));
return base64_encode($encryptedData);
}
PHP 然后给我这个警告:
PHP Warning: mcrypt_cbc() [<a href='function.mcrypt-cbc'>function.mcrypt-cbc</a>]: The IV parameter must be as long as the blocksize in /home/xxxxx/public_html/libraries/global.inc.php on line xx
我的钥匙太长了吗?应该是多少个字符?
【问题讨论】:
-
//start pad unpad functions function pad($text) { // Add a single 0x80 byte and let PHP pad with 0x00 bytes. return pack("a*H2", $text, "80"); //return $text; } function unpad($text) { // Return all but the trailing 0x80 from text that had the 0x00 bytes removed return substr(rtrim($text, "\0"), 0, -1); //return trim($text); } //end pad unpad functions -
来自manual :“此函数不应再使用,请参阅 mcrypt_generic() 和 mdecrypt_generic() 进行替换。”
标签: php encryption mcrypt