[PHP] Base64 encryption and decryption (reversible)

Base64 information encoding encryption (reversible)

 

Encryption: base64_encode

base64_encode ( string $data ) : string

Use base64 to encode data.

This kind of encoding is designed so that binary data can be transmitted through a non-pure 8-bit transport layer, such as the body of an email.

Base64-encoded data occupies about 33% more space than the original data.

 as follows:

$str = '123456';
$encodeStr = base64_encode($str);
echo $encodeStr;
// 输出:MTIzNDU2

Decryption: base64_decode

base64_decode ( string $data [, bool $strict = FALSE ] ) : string

Decode base64 encoded data.

Parameters 
* data-encoded data. 
* strict - If the input data exceeds the base64 alphabet, it returns FALSE.
$str = '123456';
$encodeStr = base64_encode($str);
echo $encodeStr . "<br>";
echo base64_decode($encodeStr);
// 结果:
// MTIzNDU2
// 123456


 

Guess you like

Origin blog.csdn.net/I_lost/article/details/104574859