I have a generic implementation of mcrypt and its not working.

Posted by Ken Mitchner on Stack Overflow See other posts from Stack Overflow or by Ken Mitchner
Published on 2010-06-17T03:38:05Z Indexed on 2010/06/17 3:43 UTC
Read the original article Hit count: 280

Filed under:
|
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($this->_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 find 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?

© Stack Overflow or respective owner

Related posts about php

Related posts about mcrypt