Base64 encryption principle)

Source: Internet
Author: User

Base64 is a feeding bit encryption method. Why is it base64? Because no matter what plaintext is (such as Chinese characters and special symbols ), encrypted passwords are only 64 characters including letters A-Z, a-Z, 0-9, and + and, after the body is encrypted, the product will generally become the original 4/3.

The base64 standard is displayed on the 24 pages of rfc2045.

Http://wenku.baidu.com/view/bd567523aaea998fcc220e8e.html

Next I will encrypt an astralidea short ast to illustrate its encryption principle.

 

 

For convenience, we use people's ways of thinking instead of computers. Below is a description.

1. Assume that there are three characters. First, replace it with a 10-digit ASCII code, and then convert it into a 2-digit code. The number of digits must be filled with 0 to ensure 8 digits.

2. Because the ASCII code size is one byte, that is, 8 bits, three eight bits. Because 3*8 = 4*6, we divide it into 4 points, each of which contains 6 digits. If the number of digits is small, 0 is used.

3. Add the first two digits of the six-digit code to two zeros. For example, after 010000 is transferred, the first two digits are 00010000. This is very important for the computer and becomes an eight-digit code.

4. Convert the four eight-bit (that is, one byte) codes according to the base64 standard in RFC. The standard table is also provided below.
In this way, we get the qvnu, that is, the ast encryption result.

The following is a standard base64 encoding table.

 

 

So what if there are 3 to 4 characters in each of them?

Base64 is defined in this way, and the rest is supplemented with "=.

For example, after the character "a" is converted to "01000001", four zeros are added to the end of the character "0" to "010000". | 010000 The table shows that two QQ differences are filled with =.

Therefore, after a password is added, it is QQ =. For 3N + 2 cases

Similarly, after as is encrypted, It is qvm =
In this way, all the situations are met.

After talking about this, we provide the code for implementing encryption. Here we can see the Concise Expression of the encryption process:

Of course, if you use the. NET library, you can directly call

Byte [] bytes = encoding. Default. getbytes ("convertstring ");
Convert. tobase64string (bytes );

You can.

Application:

 

1. because base64 can encrypt any character, we can encrypt a small program, such as a few k exe files, and then send it to the webpage, because base64 standard does not contain invalid characters, put it in any space, there should be no problem. Then, copy and decrypt the data on the other side, which saves you the trouble of uploading data to the network hard disk for various reasons (such as failed upload of viruses.

2. base64 was initially designed to prevent you from seeing what the plaintext is after encryption. Its main application is encrypted, for example, Thunder is encrypted after adding base64.

For example, I Virtualize an address http://www.astralidea.com/down.exe

We know that this address does not exist. Suppose we use base64 to simulate the thunder address?

1. Thunder adds AA and ZZ to the above address to become: aahttp: // www.astralidea.com/down.exezz

2. encrypt the above characters: qufodhrwoi8vd3d3lmfzdhjhbglkzweuy29tl2rvd24uzxhlwlo =

3. Add Thunder: // qufodhrwoi8vd3d3lmfzdhjhbglkzweuy29tl2rvd24uzxhlwlo =

You will find that the encrypted data is the same as the virtual one.

The flash get principle is the same, but the added material is [flashget].
Qq tornado simply does not add a value, and it directly performs base64 encoding on the address.

3. viewstate in ASP. NET is encrypted with base64. If you understand this, you can decrypt it to get an XML file and find the key-value pairs.

4. the base64 variant is the standard base64 mentioned above. If we replace or disrupt the content in the encryption table, it becomes the variant base64. For example, the uencode encryption method works the same way, but the encryption table is different.

.....

 

How is base64 decrypted? As long as you use your mind to write it yourself, you can write it out.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.