Simple Encrypt and Decrypt

Posted: July 31, 2015 in Uncategorized

Following code will encrypt and decrypt as per your length and data:

You can easily pass it to URL
function randomstring_ENCRYPT($post_ad_id,$length){

$characters = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$charactersLength = strlen($characters);
$randomString = ”;
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength – 1)];
}

$encode =rtrim(strtr(base64_encode($randomString.$post_ad_id), ‘+/’, ‘-_’), ‘=’);

return $encode;

}

function randomstring_DESCRPT($data,$length){

$post_ad_id = base64_decode(str_pad(strtr($data, ‘-_’, ‘+/’), strlen($data) % 4, ‘=’, STR_PAD_RIGHT));

$pid = substr($post_ad_id, $length);

return $pid;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s