Skip to content

Instantly share code, notes, and snippets.

@FLasH3r
Created May 13, 2012 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FLasH3r/2689372 to your computer and use it in GitHub Desktop.
Save FLasH3r/2689372 to your computer and use it in GitHub Desktop.
Encrypt/Decrypt Simple Class
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