Node.js中引入md5加密

概述

我们如果想要进行md5加密,可以安装md5模块。

GitHub官网:https://github.com/pvorb/node-md5

安装

安装md5包:

npm install md5

API

仅有一个md5()函数:

md5(message)

该函数的参数支持:String,Buffer,Array或者Uint8Array。

该函数的返回值是md5加密后的字符串。

使用

  • 对字符串进行加密
// 第一步,引入md5
const md5 = require('md5');

// 第二步,调用md5函数对字符串进行加密
console.log(md5('message'));// 78e731027d8fd50ed642340b7c9a63b3
  • 对Buffer进行加密
// 第一步,引入md5
const md5 = require('md5');
const fs = require('fs');

// 第二步,调用md5函数对字符串进行加密
fs.readFile('./hello.txt', function (err, buf) {
    
    
    console.log(md5(buf));
});

猜你喜欢

转载自blog.csdn.net/cnds123321/article/details/121572908