Detailed explanation of the steps for MD5 encryption of data through node.js

php中世界最好的语言
Release: 2018-05-29 13:54:56
Original
2074 people have browsed it

This time I will bring you a detailed explanation of the steps for MD5 encryption of data throughnode.js, and what are theprecautionsfor encrypting data through MD5 through node.js, as follows This is a practical case, let’s take a look at it.

md5 introduction: MD5 is a commonly used hash algorithm, mainly used to "sign" some important data. Of course, these data can be arbitrary. The final "signature" is usually a 16 or 32-digit hexadecimalstring.

In actual work development, no one will directly put the plain text of the password directly into the database. Because this approach is very unsafe, it is generally required to be MD5 encrypted! For example, a user's password is "123456" (of course, such a password has no security). After MD5 processing, it becomes:

"e10adc3949ba59abbe56e057f20f883e". The main benefits of doing this are the following two points:

1. PreventionWebsite OperationInsiders know your password and do some unethical behavior. Because many people set all their passwords to the same for convenience.

2. Prevent external attacks. If the website you registered is attacked by a hacker and you get some data from the website, you will also get a bunch of strings processed by MD5.

Note: MD5 generally cannot be decompiled. The premise is that your password should not be set too simple. This is why more and more websites now have higher and higher requirements for the passwords set by users. Not only must the password be long enough, but the password must also include numbers, large and small letters, andspecial characters. Characterstring.

This article will mainly focus on how to encrypt data with MD5 in NODE.JS:

Introduce the md5 dependency package directly into NODE:

Download and install md5 dependency package

npm install md5
Copy after login

md5 encryption example:

var md5 =require("md5"); //设置加密字符串 var passWord="if(1==1){console.log('i love you')}"; console.log(md5(passWord));//a775657889f1ad6e19178c3cd734392b
Copy after login

Of course, simply encrypting data with MD5 is not safe. , it’s best to take the data with a pinch of salt:

var md5 =require("md5"); //设置加密字符串 var passWord="if(1==1){console.log('i love you')}"; //在原来的字符串的基础上加上一些特殊文本,例如“zhangpeiyue.com" console.log(md5(passWord+"zhangpeiyue.com"));//13c22698f52329433107e75b49330484
Copy after login

MD5 encryption method in nodejs:

First one:

var crypto=require('crypto'); var md5=crypto.createHash("md5"); md5.update("abcdef"); var str=md5.digest('hex'); var s=str.toUpperCase(); //32位大写 console.log(s);
Copy after login

Second type:

var md5=require("md5") var str=md5("abcdef") //str=e80b5017098950fc58aad83c8c14978e 默认32位小写
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to use Vue to make Amap and build a real-time bus application

How to use seajs in require Writing convention

The above is the detailed content of Detailed explanation of the steps for MD5 encryption of data through node.js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!