Created
May 13, 2012 17:25
-
-
Save FLasH3r/2689372 to your computer and use it in GitHub Desktop.
Encrypt/Decrypt Simple Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EncDec { | |
private $securekey, $iv; | |
function __construct($key) { | |
$this->key = hash('sha256',$key,true); | |
$this->iv = mcrypt_create_iv(32); | |
} | |
function encrypt($input) { | |
$encData = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->key , $input, MCRYPT_MODE_ECB, $this->iv); | |
return base64_encode($encData); | |
} | |
function decrypt($input) { | |
$decData = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->key, base64_decode($input), MCRYPT_MODE_ECB, $this->iv); | |
return trim($decData); | |
} | |
} | |
$enc_dec = new EncDec("pass"); | |
$encrypted = $enc_dec->encrypt("secret data"); | |
$decrypted = $enc_dec->decrypt($encrypted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment