Showing posts with label My PHP Framework. Show all posts
Showing posts with label My PHP Framework. Show all posts

Thursday, September 22, 2011

PHP API data encryption

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;

Saturday, July 30, 2011

Eddie php framework 2.0

Will post content soon...