mcrypt_crypt和decrypt的结果不匹配

时间:2013-03-12 12:46:18

标签: php encryption mcrypt rijndael

我有两种加密和解密方法,但是输入值与解密函数的输出值不匹配,请你帮我找到问题?

private function encryptMd($md)
{
    $md = serialize($md);
    //encryption should happen here
    $md = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->secret, $md, MCRYPT_MODE_ECB);
    $md = gzcompress($md);
    $md = base64_encode($md);
    return $md;
}

private function decryptMd($md)
{
    $md = base64_decode($md);
    $md = gzuncompress($md);
    // decryption happen here
    $md = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->secret, $md, MCRYPT_MODE_ECB));
    $md = unserialize($md);
    return $md;
}

结果如下:

第一个字符串: 订单ID = 1111264&安培; cardnumber = 4012001037141112&安培; cardname =测试&安培; cardtype = VISA&安培;金额= 100安培; EXPDATE = 0214

加密字符串: eJwBgAB // 4LFthFrKDuzX7v + 90h2j24xrEnKHHxefzvh5si5yKxEJxtOAo8XG923Ako0eYP7JVH03yN9LPdb / V8JghJVi8tPvloqlEOFwDHUbwBoFGHBNvTRq0vgMRN / Wlpfk8e + UYQWV4TRYYNWNWxVLiwMFWWOk6bsESDgRBkMDQcp // OOFkg5cg ==

收到的字符串: eJwBgAB // 4LFthFrKDuzX7v + 90h2j24xrEnKHHxefzvh5si5yKxEJxtOAo8XG923Ako0eYP7JVH03yN9LPdb / V8JghJVi8tPvloqlEOFwDHUbwBoFGHBNvTRq0vgMRN / Wlpfk8e + UYQWV4TRYYNWNWxVLiwMFWWOk6bsESDgRBkMDQcp // OOFkg5cg ==

解密结果: FALSE

1 个答案:

答案 0 :(得分:0)

问题在于$ this->秘密在解密时是空的。无论如何,谢谢。