Python built-in module: base64

Source: Internet
Author: User
Tags base64

Base64 Encoding Rules:

Binary number of 24bit

|

Divided into 4 groups, insufficient to complement \x00

|

Each group is encoded in 1 bytes (denoted by a character in 64 ASCII codes), a total of 4 bytes, and insufficient compensation =



import base64a = base64.b64encode (b ' 12ABC ') print  (a) print  (str (a,  ' utf-8 ')) b  = base64.b64decode (a) print (b) print  (str (b,  ' utf-8 ')) 

Operation Result:

B ' mtjbymm= ' mtjbymm=b ' 12ABC ' 12ABC


However, there may be a ' + ' or ' \ ' number after encoding, which is not allowed in the URL, so it needs to be converted via the URL safe: +----_

Import base64a = Base64.b64encode (b ' I\xb7\x1d\xfb\xef\xff ') print (a) c = Base64.urlsafe_b64encode (b ' i\xb7\x1d\xfb\xef \xff ') print (c) Print (Base64.urlsafe_b64decode (c))

Operation Result:

B ' abcd++//' B ' abcd--__ ' B ' i\xb7\x1d\xfb\xef\xff '


Python built-in module: base64

Related Article

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.