Encryption and Decryption in PHP
Hello Readers( if any ;) ) . Encryption and Decryption is one of the most useful and widely used technique when we want to pass values through URL (or) for encrypting the sensitive data. I googled over the Internet for these functions and finally i got them. Here are the two simple functions to encrypt and decrypt the the data with a key (or) password.
First, let us see the ENCRYPT function
/** Input Parameters are
** $string- The string you want to encrypt
** $key- string(it's like a password)
**/
function encrypt($string, $key) {
$result ='';
for($i=0; $i
//enode the result using base64 function for more security
return base64_encode($result);
}
?>
Now head on to DECRYPT function.
/** Input Parameters are
** $string- The string you want to encrypt
** $key- string(it's like a password)
**/
function decrypt($string, $key) {
$result ='';
//decode the result using base64 decode function
$string = base64_decode($string);
for($i=0; $i
?>
USAGE:
//Here we are encrypting "foobar" using the key "wordpress"
$encoded = encrypt("foobar","wordpress");
//Here we are decrypting "foobar" using the key "wordpress"
$decoded= decrypt($encoded,"wordpress");
Labels: decrypt php, encrypt php, encryption decryption php, php
posted by adityachandra @ 12:55 PM,
Post a Comment