npm install crypto-js

crypto-js可用于加密。简单加密可直接如下使用:


var CryptoJS = require('crypto-js');
var hash = CryptoJS.MD5('celavie');
console.log(hash.toString());
console.log('md5 base64: ' + hash.toString(CryptoJS.enc.Base64));

var hash = CryptoJS.SHA1('celavie');
console.log(hash.toString());
console.log('sha1 base64: ' + hash.toString(CryptoJS.enc.Base64));

var hash = CryptoJS.SHA256('celavie');
console.log(hash.toString());
console.log('sha256 base64: ' + hash.toString(CryptoJS.enc.Base64));

var hash = CryptoJS.SHA512('celavie');
console.log(hash.toString());
console.log('sha512 base64: ' + hash.toString(CryptoJS.enc.Base64));

var hash = CryptoJS.SHA3('celavie');
console.log(hash.toString());
console.log('sha3 base64: ' + hash.toString(CryptoJS.enc.Base64));

详细用法参照:https://code.google.com/p/crypto-js/

    原文作者:orz71
    原文地址: https://segmentfault.com/a/1190000000516698
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞