0

我创建了两个这样的加密和解密函数

function encryption($x) {
    $key = 'SuperSecretKey';
    $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $x, MCRYPT_MODE_ECB);
    return $encrypted;
}

function decryption($y) {
    $key = 'SuperSecretKey';
    $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $y, MCRYPT_MODE_ECB);
    return $decrypted;
}

我在数据库中插入了加密密码,它工作正常,当我从数据库中检索密码时,我得到这样的加密密码

$dpass = "select Password from persons where Email='" . $_POST['name'] . "'";
$rpass = mysql_query($dpass);
$line = mysql_fetch_array($rpass);
$lpass = $line['Password'];
echo $lpass;

但问题是当你使用解密函数时

$d_pass = decryption($lpass);

echo $d_pass;

它没有给我用于密码的相同文本?你能告诉我问题是什么吗?

4

1 回答 1

0

尝试这个

function encryption($x) {
    $key = 'SuperSecretKey';
    $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $x, MCRYPT_MODE_CBC, md5(md5($key))));
    return $encrypted;
}

function decryption($y) {
    $key = 'SuperSecretKey';
    $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($y), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
    return $decrypted;
}
于 2013-06-22T16:46:17.663 回答