php-encryption
php-two-way-encryption
php-encryption
One_way Encryption
By using this, we can encode the data but we cannot decode encoded data.
md5() function: (Message-Digest 5)
By using this function, we can encode the data as 32 characters length, alphanumeric string.
Syntax
string md5 ( string $str [, bool $raw_output = FALSE ] )
Returns
md5() function returns the calculated md5 hash on success, or false on failure.
Example 1
<?php
$str = "sonoo";
echo md5($str);
?>
Output:
<?php
$str = "sonoo";
echo md5($str);
if (md5($str) == "ea866df636e6d5b4b7c9ab7b596cdd4c")
{
echo "<br>Hello javatpoint";
exit;
}
?>
Output:
Two-way Encryption
By using this concept, we can encode and decode the data. In simple terms, two-way encryption means there is both encrypt and decrypt function present. In PHP, two-way encryption is accomplished through the following function.
base64_encode()
base64_decode()
base64_encode()
This function is used to encode the given data with base64. This function was introduced in PHP 4.0.
Syntax
string base64_encode ( string $data )
Parameters
Returns:
The base64_encode() function returns the encoded data as string.
Example 1
<?php
$str= "javatpoint";
$str1= base64_encode($str);
echo $str1;
?>
Output:
<?php
$str = 'Welcome to javatpoint';
echo base64_encode($str);
?>
Output:
base64_decode():
The base64_decode() function is used to decode a base64 encoded data. This function was introduced in PHP 4.0.
Syntax
string base64_decode ( string $data [, bool $strict = FALSE ] )
Parameters
Returns:
The base64_decode() function returns the decoded data or false on failure. The returned data may be binary.
Example 1
<?php
$str = 'V2VsY29tZSB0byBqYXZhdHBvaW50';
echo base64_decode($str);
?>
Output:
<?php
$str= "amF2YXRwb2ludA==";
$str1= base64_decode($str);
echo $str1;
?>
Output:
Oldest comments (0)