Home  >  Article  >  Backend Development  >  PHP 用base64兑现加密解密

PHP 用base64兑现加密解密

WBOY
WBOYOriginal
2016-06-13 10:33:591464browse

PHP 用base64实现加密解密
      php中用base64实现加密解密:    base64_encode() 和 base64_decode() 进行加密和解密.


      语法:    string base64_encode ( string data )

      使用 base64 对 data 进行编码。设计此种编码是为了使二进制数据可以通过非纯 8-bit 的传输层传输,例如电子邮件的主体。

Base64-encoded 数据要比原始数据多占用 33% 左右的空间。

      语法:     string base64_decode ( string encoded_data )
      base64_decode() 对 encoded_data 进行解码,返回原始数据,失败则返回 FALSE。返回的数据可能是二进制的。


       例子 1. base64_encode() 示例
                   $str = 'This is an encoded string';
             echo base64_encode($str);

      ?>

       此例将显示:
       VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==


      例子 2. base64_decode() 示例

                  $str = 'VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==';
            echo base64_decode($str);

      ?>

      此例将显示:
      This is an encoded string

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn