An overview of the
Base64 is one of the most common encoding methods for transmitting 8Bit bytecode on the network. Base64 is a method to represent binary data based on 64 printable characters. For details about MIME, see RFC2045 to RFC2049. Base64 encoding is a process from binary to character that can be used to pass longer identity information in HTTP environments. Such as enabling binary data to be sent correctly as the content of an E-mail, as part of a URL, or as part of an HTTP POST request. That is, Base64 can not belong to the field of cryptography, the role is not used for encryption, it is a coding algorithm, but not readable, so it can be said to be against the gentleman not against the villain.
methods | An overview of the |
---|---|
b64encode(s, altchars=None) | rightbytes-like object sPerforms Base64 encoding and returns the encodedbytes |
b64decode(s, altchars=None, validate=False) | Decodes Base64 encodedbytes-like objectOr ASCII stringsAnd returns the decoded onebytes |
standard_b64encode(s) | codingbytes-like object s, uses the standard Base64 alphabet and returns the encodedbytes |
standard_b64decode(s) | decodingbytes-like objectOr ASCII strings, uses the standard Base64 alphabet and returns the encodedbytes |
urlsafe_b64encode(s) | codingbytes-like object s, use URL with file system security alphabet, use- As well as_ Instead of the standard Base64 alphabet+ and/ , returns the encodedbytes , the result may contain= |
urlsafe_b64decode(s) | decodingbytes-like objectOr ASCII strings, use URL with file system security alphabet, use- As well as_ Instead of the standard Base64 alphabet+ 和 / , returns the decodedbytes |
. | . |
Simple to use
The two methods we most commonly use are b64encode and b64decode-Base64 encoding and decoding, where the parameter S of B64encode must be of type byte packets (bytes). The parameter S of B64decode can be either a byte packet (bytes) or a string (STR).
Base64 encoding
S = b'I like Python'
e64 = base64.b64encode(S)
print(e64)
Copy the code
Example results:
b'SSBsaWtlIFB5dGhvbg=='
Copy the code
Base64 decoding
S = 'SSBsaWtlIFB5dGhvbg=='
d64 = base64.b64decode(S)
print(d64)
Copy the code
Example results:
b'I like Python'
Copy the code