CryptoJS 加密库分享

CryptoJS加密库网盘百度网盘下载地址:

链接: https://pan.baidu.com/s/1yJ9aZthAnNqKTy79gsKeHg 提取码: 4ahp 

 

加密库函数 调用和总结:

parse和stringify
var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
var wordArray = CryptoJS.enc.Hex.parse(hexString);
var wordArray = CryptoJS.enc.Base64.parse(base64String);

var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
var hexString = CryptoJS.enc.Hex.stringify(wordArray);
var base64String = CryptoJS.enc.Base64.stringify(wordArray);

消息摘要算法
var hash = CryptoJS.MD5(message);
var hash = CryptoJS.MD5(wordArray);
var hmac = CryptoJS.HmacMD5(message, key);

var hash = CryptoJS.SHA1(message);
var hash = CryptoJS.SHA1(wordArray);
var hmac = CryptoJS.HmacSHA1(message, key);

var hash = CryptoJS.SHA224(message);
var hash = CryptoJS.SHA224(wordArray);
var hmac = CryptoJS.HmacSHA224(message, key);

var hash = CryptoJS.SHA256(message);
var hash = CryptoJS.SHA256(wordArray);
var hmac = CryptoJS.HmacSHA256(message, key);

var hash = CryptoJS.SHA3(message);
var hash = CryptoJS.SHA3(wordArray);
var hmac = CryptoJS.HmacSHA3(message, key);

var hash = CryptoJS.SHA384(message);
var hash = CryptoJS.SHA384(wordArray);
var hmac = CryptoJS.HmacSHA384(message, key);

var hash = CryptoJS.SHA512(message);
var hash = CryptoJS.SHA512(wordArray);
var hmac = CryptoJS.HmacSHA512(message, key);

对称加密算法
var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
var plaintext  = CryptoJS.AES.decrypt(ciphertext, key, cfg);

var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
var plaintext  = CryptoJS.DES.decrypt(ciphertext, key, cfg);

var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
var plaintext  = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);

var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
var plaintext  = CryptoJS.RC4.decrypt(ciphertext, key, cfg);

加密模式
CBC ECB CFB OFB CTRGladman(CTR)

填充方式
NoPadding ZeroPadding Pkcs7(Pkcs5) Iso10126 Iso97971 AnsiX923

wordArray转换到字符串
var string = wordArray + '';
var string = wordArray.toString();
var string = wordArray.toString(CryptoJS.enc.Utf8);

另外的调用方式
var hasher = CryptoJS.algo.SHA256.create();
hasher.reset();
hasher.update('message');
hasher.update(wordArray);
var hash = hasher.finalize();
var hash = hasher.finalize('message');
var hash = hasher.finalize(wordArray);

var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
hmacHasher.reset();
hmacHasher.update('message');
hmacHasher.update(wordArray);
var hmac = hmacHasher.finalize();
var hmac = hmacHasher.finalize('message');
var hmac = hmacHasher.finalize(wordArray);

你可能感兴趣的:(JS加密解密)