Detailed Node.js API series Crypto encryption Module (1) __js

Source: Internet
Author: User
Tags md5 md5 encryption sha1 sha1 encryption password protection
MD5 Encryption Algorithm Introduction to Algorithms

The full name of MD5 is message-digest algorithm 5 (Information-Digest algorithm), in the early 90 by MIT Laboratory for Computer and RSA Data Security Inc, Ronald L. Riv EST developed and developed by MD2, Md3 and MD4. Its role is to allow bulk information to be "compressed" into a confidential format (that is, to transform an arbitrary length of a byte string into a long, large integer) before signing the private key with the digital signature software. 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 in size. is an irreversible algorithm. algorithm features two different plaintext will not get the same output value MD5 results can not reverse plaintext, irreversible security

From a security point of view, MD5 output of 128 bits, if the use of pure brute force attack to find a message with a given hash value of the computational difficulty of 2128, with 1 billion messages per second to test the computer will take 1.07x1022 years. In the case of a birthday attack, finding two messages with the same hash value requires 264 messages, and it takes 585 years for a computer to test 1 billion messages per second.

Practical application, for example I know ' Password ' MD5 value is 5f4dcc3b5aa765d61d8327deb882cf99, then I 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 in the identification system for password protection has been a long time, most hackers also have the hash for the preparation of the corresponding database for retrieval, this database called the 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 value is 5f4dcc3b5aa765d61d8327deb882cf99
SHA1 Algorithm Introduction to Algorithms

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 binary string of fixed length. The cryptographic hash function has the property that it is not possible to find two different inputs with the same value in the calculation, that is, the hash value of the two sets of data matches only if the corresponding data matches. A small amount of change in the data produces unpredictable and significant 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 in size. 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 ');
different points between MD5 and SHA1MD5 uses a small-end sort Little-endian,sha1 Big-endian MD5 The last generated summary information is 16 bytes, and the SHA1 is 20 bytes.

Source: http://blog.whattoc.com/2013/09/20/nodejs_api_crypto1/

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.