Introduction to Algorithms
MD5 's full name is Message-digest algorithm 5 (Information-Digest algorithm), in the early 90 by MIT Laboratory for Computer Science and RSA Data Security Inc Ronald L. Riv EST developed, through the development of MD2, MD3 and MD4. Its role is to allow bulk information to be "compressed" into a confidential format before signing a private key with a digital signature software (that is, converting an arbitrary-length byte string into a long, large integer). Whether it's MD2, MD4 or MD5, They all need to get a random length of information and produce a 128-bit summary of the information.
The hash value of the MD5 algorithm is 128 bits. is an irreversible algorithm.
Algorithm features
- Two different plaintext does not get the same output value
- MD5 results cannot be reversed clear, irreversible
Security
From a security standpoint, the output of the MD5 is 128 bits, and if a pure brute force attack is used to find a message with a given hash value, the computational difficulty is 2128, and the computer that can experiment with 1 billion messages per second takes 1.07x1022 years. If you use the Birthday attack method to find two messages with the same hash value, you need to experiment with 264 messages, and a computer with 1 billion messages per second will take 585 years.
Practical application, for example I know ' Password ' MD5 value is 5f4dcc3b5aa765d61d8327deb882cf99, then I will use a database to save, as long as I see 5f4dcc3b5aa765d61d8327deb882cf99, I know this is the password ' Password ' uses the value after MD5 processing, the original password is ' password '. MD5 used for password protection in identity authentication system It's been a long time, most hackers also have to prepare the corresponding database for this hash method to counter-check, the database called Rainbow Table, MD5 security greatly weakened.
MD5 Encryption Routines
var crypto = require(‘crypto‘);var content = ‘password‘var md5 = crypto.createHash(‘md5‘);md5.update(content);var d = md5.digest(‘hex‘); //MD5值是5f4dcc3b5aa765d61d8327deb882cf99
Introduction to SHA1 algorithm algorithm
The full name of SHA1 is secure Hash algorithm (Secure Hash algorithm). The cryptographic hash function maps a binary string of any length to a small, fixed-length binary string. The cryptographic hash function has a property that is unlikely to find two different inputs for the same value as the hash column, meaning that the hashes of the two sets of data match only when the corresponding data matches. A small number of changes to the data produce unpredictable changes in the hash value. So it's hard to find clues from the encrypted text.
The hash value of the SHA1 algorithm is 160 bits. is an irreversible algorithm.
SHA1 Encryption Routines
var crypto = require(‘crypto‘);var content = ‘password‘var shasum = crypto.createHash(‘sha1‘);shasum.update(content);var d = shasum.digest(‘hex‘);
The difference between MD5 and SHA1
- MD5 uses the small end sort LITTLE-ENDIAN,SHA1 uses the big-endian sort Big-endian
- MD5 the last generated digest information is 16 bytes, and SHA1 is 20 bytes.
Initial knowledge of encryption algorithm