base64 Python3 built-in module of the encoding and decoding method Summary

14035218-7f8cd0762d0ca6f6.jpg
172.jpg

Outline

Base64 is one of the most common network for the transmission of 8Bit encoding bytecode, Base64 is based on 64 printable characters to binary data representation. To see RFC2045 ~ RFC2049, MIME above detailed specification. Base64 encoded character from binary to process, it can be used to deliver a longer identification information HTTP environment. Such that the binary data can be correctly transmitted as the e-mail content, as part of the URL, or as part of an HTTP POST request.
That fact can not be attributed base64 password field, the role is not used for encryption, which is a kind 编码算法, but having not readable, it can be said that the anti-anti-villain is not a gentleman.

method Outline
b64encode(s, altchars=None) Of bytes Object-like S be Base64 encoded, and the encoded returnbytes
b64decode(s, altchars=None, validate=False) Base64 decoding the coded bytes-like object or ASCII string s and returns the decodedbytes
standard_b64encode(s) Encoding bytes Object-like S , using standard Base64 encoded return of the alphabet andbytes
standard_b64decode(s) Decoding bytes-like object or ASCII string S , and return to use the standard alphabet Base64 encoded thebytes
urlsafe_b64encode(s) Encoding Object bytes-like S , using the URL and the file system security alphabet used -and _instead of the standard alphabet Base64 +and /returns the encoded bytesresult may contain=
urlsafe_b64decode(s) Decoding bytes-like object or ASCII string S , using the URL and the file system security alphabet used -and _instead of the standard alphabet Base64 +and /returns the decodedbytes
... ...

Simple to use

The two most commonly used methods i.e. b64encodeand b64decode-Base64 encoding and decoding, wherein the parameter s b64encode type must be byte packets (bytes). b64decode parameter s may be a byte packets (bytes), or a string (str).

Base64 encoding

S = b'I like Python'
e64 = base64.b64encode(S)
print(e64)

Sample results:

b'SSBsaWtlIFB5dGhvbg=='

Base64 decoding

S = 'SSBsaWtlIFB5dGhvbg=='
d64 = base64.b64decode(S)
print(d64)

Sample results:

b'I like Python'

Guess you like

Origin blog.csdn.net/weixin_33843947/article/details/90945502