Below is the mcrypt method that I use to do for API data encryption
define('KRYPT_KEY', 'nextblog');
function encrypt($string) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return mcrypt_encrypt(MCRYPT_BLOWFISH, KRYPT_KEY, $string, MCRYPT_MODE_ECB, $iv);
}
/*** decrypt string ***/
function decrypt($crypttext) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return mcrypt_decrypt(MCRYPT_BLOWFISH, KRYPT_KEY, $crypttext, MCRYPT_MODE_ECB, $iv);
}
$userid = "94017";
$encodeduserid = base64_encode(encrypt($userid));
print 'Encoded Userid: ' . $encodeduserid;
$decodeduserid = trim(decrypt(base64_decode($encodeduserid)));
print 'Decoded Userid: ' . $decodeduserid;
No comments:
Post a Comment
please leave your comment...