Created
May 10, 2013 01:49
-
-
Save LeoDT/5551897 to your computer and use it in GitHub Desktop.
php encrypt to hex
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 hex2bin($data) | |
{ | |
return pack("H" . strlen($data), $data); | |
} | |
function encrypt($key, $data) | |
{ | |
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND); | |
return bin2hex(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, $iv)); | |
} | |
function decrypt($key, $data) | |
{ | |
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND); | |
return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, hex2bin($data), MCRYPT_MODE_ECB, $iv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment