Created
April 30, 2015 14:16
-
-
Save alexcorvi/2ff0bc1dba20553171c4 to your computer and use it in GitHub Desktop.
PHP Encrypt/Decrypt Function
This file contains 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
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