Hash and encryption (1), hash Encryption

Source: Internet
Author: User

Hash and encryption (1), hash Encryption

Disclaimer: This article is based on the basic principles and differences of Hash and encryption and the learning and arrangement of engineering applications.


1. Differences between hash and Encryption

(1) hash: Convert the target textSame length, irreversibleOr message digest );

(2) encryption: Convert the target textDifferent Lengths, reversible.

In fact, the same hash algorithm is used, regardless of the size of the target text, to obtain a fixed length of results. The encryption algorithm is usually proportional to the length of the target text.


2. mathematical basis of hash and Encryption

(1) hash algorithm: R = H (S) isMulti-to-one ing, Multiple different S can use the hash algorithm H to get the same R. So there is no inverse ing, so that an R can obtain a unique S.

A well-designed hash algorithm is difficult to find the target text collision from the hash results. In addition, a good hash algorithm is extremely sensitive to changes to the target text.

What is collision? For hash algorithm H, if S1 is not equal to S2, but H (S1) is equal to H (S2), S1 and S2 are considered to collide with each other.

(2) encryption algorithm: R = E (S, Ke) isOne-to-one ingOne second, combined with the encryption key Ke, can only obtain the unique ciphertext R. On the contrary, a single R can only obtain the unique S when used together to decrypt the key Kd.

A well-designed encryption algorithm should be a "one-way trap function". The characteristics of a one-way trap function: Even if you know the function itself, it is difficult to obtain the corresponding independent variable from the function value. However, once you know the traps, the independent variables are easy to calculate.

In short, a good encryption algorithm should be difficult to obtain the plaintext from the ciphertext, but once the key is known, it is easy to obtain the plaintext from the ciphertext.

In the anti-attack aspect of encryption algorithms, it is often assumed that attackers know the encryption algorithms and ciphertext, so we should protect plaintext and key.


3. Application of hash and encryption in Software

(1) data protection is the most common application of hash and encryption in software development.

To implement data protection, select hash or encryption:

If the protected dataVerify by comparison only, Do not need to be restored to plain text in the future, use Hash;

If the protected dataNeed to be restored to plain text, Use encryption;

If you forget the password and the website asks you to enter a new password, it should use a hash;

If you forget the password and the website sends you the original password, encryption should be used;

(2) Data Protection using a simple hash:



For example, you can map the registered passwords to the database, and map the obtained strings to the database, compare the obtained collection string with the registration password collection string in the database. If the character string is the same, the logon is successful.

The most common hashing algorithms are MD5 and SHA1.



Related Article

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.