php encrypt and decrypt function in simple

php encrypt and decrypt

Php Encrypt and Decrypt Function its very useful to php developer simple works.

 


<?php
define("ENCRYPTION_KEY", "!@#$%^&*");
$string = "indianjobtips.com";

echo $encry  = encrypt($string, ENCRYPTION_KEY);
echo "/t";
echo $decrypted = decrypt($encry , ENCRYPTION_KEY);


function encrypt($pure_string, $encryption_key) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, utf8_encode($pure_string), MCRYPT_MODE_ECB, $iv);
return $encrypted_string;
}


function decrypt($encrypted_string, $encryption_key) {
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv);
return $decrypted_string;
}
?>

Related Posts

Advertisement

No comments.

Leave a Reply