Skip to content

Instantly share code, notes, and snippets.

@alexcorvi
Created April 30, 2015 14:16
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 alexcorvi/2ff0bc1dba20553171c4 to your computer and use it in GitHub Desktop.
Save alexcorvi/2ff0bc1dba20553171c4 to your computer and use it in GitHub Desktop.
PHP Encrypt/Decrypt Function
function encrypt($mprhase) {
$MASTERKEY = "some key here";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $MASTERKEY, $iv);
$crypted_value = mcrypt_generic($td, $mprhase);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return base64_encode($crypted_value);
}
function decrypt($mprhase) {
$MASTERKEY = "some key here";
$td = mcrypt_module_open('tripledes', '', 'ecb', '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $MASTERKEY, $iv);
$decrypted_value = mdecrypt_generic($td, base64_decode($mprhase));
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $decrypted_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment