这是我的加密课程
define('KEY', '1234567891111111');
class crypto
{
//private static $key= 'DocT0r$t@y';
public function encrypt ($payload) {
$iv = mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC),
MCRYPT_DEV_URANDOM
);
//$iv = mcrypt_create_iv(IV_SIZE, MCRYPT_DEV_URANDOM);
$crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, KEY, $payload, MCRYPT_MODE_CBC, $iv);
$combo = $iv . $crypt;
$garble = base64_encode($iv . $crypt);
//return trim($garble,'�');
return $garble
}
public function decrypt ($garble) {
$combo = base64_decode($garble);
$iv = substr($combo, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$crypt = substr($combo, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), strlen($combo));
$payload = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, KEY, $crypt, MCRYPT_MODE_CBC, $iv);
//return trim($payload,'�');
return $payload
}
}
这就是我如何打电话给我的班级并检查出来
$e=crypto::encrypt($pwd);
$d=crypto::decrypt($e);
echo $e." ".$d;
if($d==$pwd)
echo "<br>yes";
else
echo "<br>no";
exit();
当我检查可能会在firebug输出显示我
a9MF8SdTrsedILnV2fyNucYqUaZG9yvYxJcRbYOwJbg =123�������������
否
(这里123是我想要加密/解密的文本)。 任何建议我做错了什么或为什么它是mot工作?