Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
introduce
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. Base64 encoding is unreadable and can be read only after decoding.
Base64 is widely used in various fields of computer because of the above advantages, but because the output content includes more than two “symbol class” characters (+, /, =), different application scenarios are separately developed Base64 “varieties”. To unify and normalize the output of Base64, Base62x is regarded as an improved version of unsymbolized Base64.
In python base64
Encode the URL as base64
# to transfer string encoded in base64, to convert the string into binary data url = "https://www.cnblogs.com/songzhixue/" bytes_url = url. The encode str_url = (" utf-8 ") Base64. B64encode (bytes_url) # encoded parameters must be binary data print (str_url) b 'aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vc29uZ3poaXh1ZS8 ='Copy the code
Decoding base64
# base64 decoding into string import base64 url = "aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vc29uZ3poaXh1ZS8 =" str_url = base64.b64decode(url).decode("utf-8") print(str_url) 'https://www.cnblogs.com/songzhixue/'Copy the code
conclusion
- Base64 in Python returns an array of bytes, both encoded and decoded
- Decoding is a string, encoding is an array of bytes