Base64 Decode, Base64 Encode, Base64 Encryption/Decryption
- Conversion rules: During Base64 conversion, 3 bytes (3*8bit = 24bit) of data are placed successively into a 24bit buffer, with the first byte occupying the high order. If the data is less than 3 bytes, the remaining bits in the buffer are filled with 0. Then, 6 bits are taken out each time (24/6 = 4). Since 2^6=64, according to its value, select the corresponding character from these 64 characters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
as the encoded output. Continue until all input data is converted. When the original data length is not a multiple of 3 bytes, if there is 1 input data remaining, add 2 "=
" after the encoding result; if there are 2 input data remaining, add 1 "=
" after the encoding result; if there is no remaining data, add nothing.
- Base64 encoded data is slightly longer than the original data, approximately 4/3 of the original length.
- Base64 encoding may produce different results for the same character under different encodings.
- Because of the encoded
+/=
characters, standard Base64 is not suitable for direct transmission in URLs. There are some Base64 variants that convert +/
and other symbols to other symbols (such as _-
), so they can be safely transmitted in URLs (URL Safe).