Current location - Quotes Website - Personality signature - 2. Hash encryption &; Base64 encryption
2. Hash encryption &; Base64 encryption
I. Hash Hash

Hash function? MD5 sha 1/256/5 12 HMAC

Characteristics of hash:

? 1. The algorithm is public.

? 2. The result is the same for the same data.

? 3. For different data operations, such as MD5, the result is 128 bits, which is expressed in hexadecimal with 32 characters, and the operation cannot be reversed.

1.MD5 encryption

Features of MD5 encryption:

Irreversible operation

The result of encrypting different data is a fixed-length 32-bit character (no matter how big the file is).

Encrypt the same data and get the same result (that is, copy).

Anti-modification: information fingerprint, any modification to the original data, even if only one byte is modified, the MD5 value obtained is quite different.

Weak anti-collision: given the original data and its MD5 value, it is difficult to find a data with the same MD5 value (that is, forged data).

Strong anti-collision: it is difficult to find two different data and make them have the same MD5 value.

MD5 application:

Consistency verification: MD5 regards the whole file as a large text message, and generates a unique MD5 message digest through an irreversible string transformation algorithm, just as everyone has their own unique fingerprint, and MD5 generates a unique digital fingerprint for any file.

Then the problem is coming. Do you think this MD5 encryption is safe? It's not really safe. If you don't believe me, you can try this website: md5 crack website. It can be said that you cracked your MD5 encryption with a swish!

2.SHA encryption

Secure hash algorithm is mainly suitable for digital signature algorithm DSA defined in digital signature standard DSS. SHA 1 will generate a message digest of 160 bits for messages with a length of less than 2 64 bits. When a message is received, the message digest can be used to verify the integrity of the data. During transmission, the data is likely to change, so different message digests will be generated at this time. In addition to SHA 1, there are SHA256 and SHA5 12.

Second, base64 encryption.

1.Base64 Description

Description: Base64 can be the cornerstone of cryptography, which is very important.

Features: Any binary data can be Base64 encoded.

Results: All data can be encoded into a text file, which can only be represented by 65 characters.

65 characters: A~Z a~z 0~9+/=

Changes of file data after base64 encoding: the encoded data ~ = 4/3 of the data before encoding, which will be about 1/3 larger.

2. Base64 encoding and decoding on the command line.

Code: base 64123.png-o123.txt.

Decoding: base64123.txt-otest.png-d.

2.Base64 coding principle

1) converts all characters into ASCII code;

2) converting ASCII code into 8-bit binary;

3) Grouping 3 binary bits into a group (0 after less than 3 bits) * * * 24 bits, and then dividing them into 4 groups with 6 bits in each group;

4) Add two zeros before the 6-bit binary to form 8 bits;

5) converting zero-filled binary into decimal;

6) obtaining the Base64 code corresponding to decimal from the Base64 code table;

Description of treatment process:

A. During conversion, three bytes of data are continuously put into the 24-bit buffer, with the first byte occupying the high position.

B if the data is less than 3 bytes, the remaining bits in the buffer will be padded with zeros. Then, take out 6 bits at a time, and look up the table according to their values to select the corresponding characters as coded output.

C, continuing until all input data are converted.