Base64 principle

I looked at data encryption recently, and looked at it from the most basic Base64. Although many people on the Internet have implemented it with code, if they only use it without knowing the principle, it will not make much progress. So I looked for the principle of Base64 encoding and found that This blogger's article is very good, and I deliberately summarize and share it.

http://www.cnblogs.com/hongru/archive/2012/01/14/2321397.html

 Through learning, it is found that the encoding process of Base64 is as follows:

  1. The string to be encoded is grouped by 3 8bit characters
  2. Get the ASCII encoding of a character
  3. Convert ASCII code to 8bit binary to get 3*8=24bit byte group
  4. Divide the 24-bit group into 4-bit bytes, and fill in two 0s in the high bits of each 6-bit byte to get 4 8-bit groups
  5. Then convert these 4 8bit groups into decimal, and compare with the BASE64 code table to get the corresponding code.

Note: 1. Each Chinese character exceeding 8bit cannot be base64 encoded

           2. If the length of the encoded character is not a multiple of 3, in the third step, if it is not enough, replace it with 0, and get =

 

   Finally, thank the blogger for sharing the summary.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992722&siteId=291194637