Python tutorial: base64 Python3 built-in modules of the encoding and decoding method Summary

Python tutorial: base64 Python3 built-in modules of the encoding and decoding method Summary

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, it is a coding algorithm, but have not readable, it can be said that the anti-anti-villain is not a gentleman.

Python tutorial: base64 Python3 built-in modules of the encoding and decoding method Summary

 

Simple to use

Two most commonly used methods i.e. b64encode and 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'

More Python tutorials will continue to update everyone to share Oh!

Guess you like

Origin www.cnblogs.com/cherry-tang/p/11008476.html