天天看點

Node.js:MD5加密字元串

方式一:crypto

const crypto = require('crypto');

const hash = crypto.createHash('md5');

// 可任意多次調用update():
hash.update('Hello ');
hash.update('world!');

console.log(hash.digest('hex'));
// 86fb269d190d2c85f6e0468ceca42a20      

方式二:js-md5

// $ npm install js-md5
const md5 = require('js-md5');

console.log(md5("Hello world!"));
// 86fb269d190d2c85f6e0468ceca42a20
      

如果是在Vue項目中使用:

import md5 from 'js-md5';

Vue.prototype.$md5 = md5;

this.$md5("加密内容")      

繼續閱讀