When we apply both the encryption and decryption functions to some data, we call it two-way encryption. In PHP, we can use the following two functions to perform two-way encryption.
base64_encode()
base64_decode()
base64_encode
functionWe can use the base64_encode
function to encode the given data or string with the base 64.
string base64_encode ( string $array )
array
: This is the array or string we need to encode.This function will return the encoded data of a given string.
<?php$arr = "Encrypted String";$temp = base64_encode($arr);echo $temp;?>
base64_decode
functionWe can use the base64_decode
function to decode the base 64 encoded data.
string base64_decode ( string $array)
array
: This is the data we need to decode.This function will return the decoded data.
<?php$str = 'RW5jcnlwdGVkIFN0cmluZw==';echo base64_decode($str);?>
Line 2: We declare a string and store encrypted data in it.
Line 3: We call the decryption function and pass the string to the function.
Line 4: We print the decrypted string.