npm install crypto-js

3516 查看

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/