开发者

I have a generic implementation of PHP mcrypt module and its not decrypting

class Crypt_Data {

    protected $_mcrypt=null;
    protected $_iv=null;
    protected $_key=null;

    public function __construct() {
            $this->_mcrypt = mcrypt_module_open('rijndael_256', '', 'cbc', '');
            $key_size = mcrypt_enc_get_key_size($this->_mcrypt);
            for($i=0;$i<$key_size;$i++) $test_key .= "0";
            $this->_iv = $test_key;
            $this->_key = $test_key;
            mcrypt_generic_init($this->_mcrypt,$this->_key,$this->_iv);
    }

    public function dataEncrypt($data) {
            return base64_encode(mcrypt_generic($t开发者_StackOverflow社区his->_mcrypt, $data));
    }
    public function dataDecrypt($data) {
            return mdecrypt_generic($this->_mcrypt, base64_decode($data));
    }
}

$crypt = new Crypt_Data();
$string = "encrypt me";
$encrypted = $crypt->dataEncrypt($string);
echo $encrypted."<BR>";

$decrypted = $crypt->dataDecrypt($encrypted);
echo $decrypted."<BR>";

output:

JJKfKxZckkqwfZ5QWeyVR+3PkMQAsP0Gr1hWaygV20I=

qÌÌi_ÖZí(®`iÜ¥wÝÿ ô0€Í6Ÿhf[%ër

No idea why this isn't working, everything seems to be fine on my end.. i tried decrypting it with mcrypt_cbc(); and it decrypted it properly.. so it has something to do with my mdecrypt_generic.. any ideas?


You need to run mcrypt_generic_init to reset all buffers with the same values again before mdecrypt_generic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜