Simple mcrypt encrypt & decrypt functions for PHP : How to
16 Sep 2011After more searching through the php.net and stackoverflow comments below is the simplest way i have come around to encrypt & decrypt info in PHP
It works and only 1 line per function
<?php
$text ='some text';
$salt ='whatever_you_want';
function simple_encrypt($text,$salt)
{
return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
function simple_decrypt($text,$salt)
{
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
?>
Refer gist for comments https://gist.github.com/justinkelly/1222159