前面简单描述了第三方模块md5的加密,今天来了解一下,node原生API加密模块crypto
const crypto = require('crypto');
const hash = crypto.createHash('sha512');
hash.update('hello ');
console.log(hash.digest('hex'));
模块来自原生node,因此无需进行npm模块下载,只需要进行require引入就行!
const crypto = require('crypto');
指定加密类型,这里支持(md5,sha1,sha256,sha512,ripemd160),这里以sha512为例
const hash = crypto.createHash('sha512');
hash.update()表示传入需要加密的字符串
hash.update('hello ');//传入需要加密的内容
返回加密后结果使用hsh.digest对象,输出类型可以hex(默认常规数字字母小写),base64和latin1
console.log(hash.digest('hex'));//表示打印下hello的加密结果
还有就是前几天为大家简单介绍过的引入第三方md5模块进行加密,如有不足,谢谢大家反馈!!!