PHP BASE64 encoding/decoding

Source: Internet
Author: User

First, how to use PHP

// Encrypt $str = ' This was an encoded string '; Echo Base64_encode ($str); // decryption $str = ' vghpcybpcybhbiblbmnvzgvkihn0cmluzw== '; Echo Base64_decode ($str);

Second, Base64 code description
1. BASE64 encoding requires 3 8-bit bytes (3*8=24) to be converted to 4 6-bit bytes (4*6=24), followed by 6 two in front of 0 bits, forming a 8-bit byte form. If the remaining characters are less than 3 bytes, then 0 is populated with the output character using ' = ', so there may be 1 or 2 ' = ' At the end of the encoded text output.

2, in order to ensure the output of the encoded bit readable characters, BASE64 developed an encoding table for unified conversion. The size of the encoded table is 2^6=64, which is also the origin of the Base64 name.

Three, BASE64 encoding table

PHP BASE64 encoding/decoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.