When I decrypt something encrypted with this function, the decrypted version doesn't equal the original.
class AES256encryption {
var $secret = '';
var $cipher_key = '';
function AES256encryption($secret='') {
if (empty($secret)) {
global $secret;
if (empty($secret)) {
$secret = "some random secret string";
}
}
$this->secret = $secret;
}
function gen_cipher() {
if (empty($this->cipher_key)) {
$this->cipher_key = substr(sha1($this->secret),0,20);
}
}
function mciv() {
return mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND);
}
function encrypt($text) {
$this->gen_cipher();
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->cipher_key, $text, MCRYPT_MODE_CBC, $this->mciv())));
}
function decrypt($text) {
$this->gen_cipher();
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->cipher_key, base64_decode($text), MCRYPT_MODE_CBC, $this->mciv()));
}
}