What is Base64?
Base64 is an encoding method that converts binary data into displayable characters in the ASCII character set for transmission and storage without compromising data integrity. Base64 encoding is reversible, meaning that the encoded data can be restored to the original binary data.
Base64 encoding table
Base64 encoding64 characters were used, including 26 uppercase letters, 26 lowercase letters, 10 numbers, and two special characters "+" and "/". Here's the full Base64 encoding table:
- Uppercase and lowercase letters (52 in total): A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u、v、w、x、y、z。
- Numbers (10 in total): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.
- Symbols (2 in total): +, /.
Base64 special characters
Base64 encoding contains twoSpecial characters "+" and "/", which have ASCII codes of 43 and 47 in the character set, respectively. These two characters are where Base64 encoding tends to cause problems, as some software systems do not recognize them. In practice, it is sometimes necessary to replace these two special characters with other characters, such as when using Base64 encoding in a URL, you need to replace "+" with "-" and "/" with "_".
How Base64 is encoded
Base64 encoding groups binary data into groups of every 6 bits, and the values of each group are used as indexes to find the corresponding characters in the Base64 encoding table, so that the encoded string is obtained. If the grouped data is less than 6 bits, add "0" at the end to make up 6 bits, inThe result is indicated by "="。
Base64 applications
Base64 is widely used. In network transmission, data needs to be Base64 encoded to address these issues due to certain protocols or software imposing restrictions on the transmitted data format. For example, in email, Base64 encoding is required because the mail transfer protocol only supports text format and binaries must be encoded as ASCII characters to be transferred. In addition, Base64 encoding is often used when transferring parameters in URLs to avoid character set incompatibilities.
|