1

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

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;
}

结果如下:

第一个字符串:orderid=1111264&cardnumber=4012001037141112&cardname=Test&cardtype=VISA&amount=100&expdate=0214

the encrypted string: eJwBgAB//4LFthFrKDuzX7v+90h2j24xrEnKHHxefzvh5si5yKxEJxtOAo8XG923Ako0eYP7JVH03yN9LPdb/V8JghJVi8tPvloqlEOFwDHUbwBoFGHBNvTRq0vgMRN/Wlpfk8e+UYQWV4TRYYNWNWxVLiwMFWWOk6bsESDgRBkMDQcp//OOFkg5cg==

the recieved string: eJwBgAB//4LFthFrKDuzX7v+90h2j24xrEnKHHxefzvh5si5yKxEJxtOAo8XG923Ako0eYP7JVH03yN9LPdb/V8JghJVi8tPvloqlEOFwDHUbwBoFGHBNvTRq0vgMRN/Wlpfk8e+UYQWV4TRYYNWNWxVLiwMFWWOk6bsESDgRBkMDQcp//OOFkg5cg==

解密结果:FALSE

4

1 回答 1

0

问题在于 $this->secret 在解密时为空。不管怎么说,还是要谢谢你。

于 2013-03-12T14:42:56.000 回答