What is base64?
As defined by RFC2045, Base64 is defined as: the Base64 content transfer encoding is designed to describe an arbitrary sequence of 8-bit bytes as a form that is not easily recognizable by humans. (The Base64 content-transfer-encoding is designed to represent arbitrary sequences of octets in a form that need not being HU Manly readable.)
The characters used include 26 uppercase and lowercase letters, plus 10 digits, and a plus sign "+", a slash "/", a total of 64 characters, and an equal sign "=" to use as a suffix.
Second, the role of Base64
- The implementation of simple data encryption, so that users can not see the real data at a glance, the complexity of the Base64 algorithm is small, the efficiency is relatively high.
- Some systems or applications that use only ASCII characters, such as email, need to encode data using Base64
The above is excerpted from http://www.cnblogs.com/apm70/articles/2358569.html
Three, base64 principle
Base64 requires that every three bytes of 8Bit be converted to four 6Bit bytes (3*8 = 4*6 = 24), and 6Bit is then added two bits high 0, which makes up four 8Bit bytes, that is, the converted string will theoretically be 1/3 longer than the original one. The encoding principle is as follows:
(1) The encoding of Base64 is based on the length of the string, in a group of 3 characters per 8bit,
(2) Then for each group, first get the ASCII encoding for each character,
(3) Then convert the ASCII encoding to 8bit binary to get a set of 3*8=24bit bytes
(4) Then divide the 24bit into 4 6bit bytes, and fill in front of each 6bit byte two high 0, get 4 8bit bytes
(5) then convert the 4 8bit bytes into 10 binary, control the BASE64 encoding table, the corresponding encoded characters.
Four, base64 character mapping table
V. Base64 routines
//a single byte byte[] B =New byte[] {0x01}; strings = convert.tobase64string (b,0,1); byte[] be =convert.frombase64string (s); //two bytes byte[] bs =New byte[] {0x01,0x02}; stringSS = Convert.tobase64string (BS,0,2); //three bytes byte[] BSS =New byte[] {0x01,0x02,0x03 }; stringSSS = convert.tobase64string (BSS,0,3);
Daily must-read (2)--base64