大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
CryptoJS简单使用. 简单看下几种加密和哈希函数.
- md5
- sha1
- ase
- base
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CryptoJS</title>
<script src="js/CryptoJS%20v3.1.2/components/core.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/md5.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/evpkdf.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/enc-base64.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/cipher-core.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/aes.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/hmac.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/sha1.js"></script>
<script src="js/CryptoJS%20v3.1.2/components/sha256.js"></script>
</head>
<body>
<div id="content"></div>
<script> var md5 = CryptoJS.MD5("Message").toString(CryptoJS.enc.Hex); console.log("md5 = %s", md5); var sHA1 = CryptoJS.SHA1("Message").toString(CryptoJS.enc.Hex); console.log("sHA1 = %s", sHA1); var sHA256 = CryptoJS.SHA256("Message").toString(CryptoJS.enc.Hex); console.log("sHA256 = %s", sHA256); var hmacMD5 = CryptoJS.HmacMD5("Message", "Secret Passphrase").toString(CryptoJS.enc.Hex); console.log("hmacMD5 = %s", hmacMD5); var hmacSHA1 = CryptoJS.HmacSHA1("Message", "Secret Passphrase").toString(CryptoJS.enc.Hex); console.log("hmacSHA1 = %s", hmacSHA1); var aesEncrypt = CryptoJS.AES.encrypt("Message", "Secret Passphrase"); console.log("aesEncrypt = %s", aesEncrypt.iv.toString(CryptoJS.enc.Hex)); var aesDecrypt = CryptoJS.AES.decrypt(aesEncrypt, "Secret Passphrase"); console.log("aesDecrypt = %s", aesDecrypt.toString(CryptoJS.enc.Utf8)); // base64 encrypt var rawStr = "hello world!"; var wordArray = CryptoJS.enc.Utf8.parse(rawStr); var base64 = CryptoJS.enc.Base64.stringify(wordArray); console.log('base64Encrypt = ', base64); // base64 decrypt var parsedWordArray = CryptoJS.enc.Base64.parse(base64); var parsedStr = parsedWordArray.toString(CryptoJS.enc.Utf8); console.log('base64Decrypt = ',parsedStr); </script>
</body>
</html>
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/213491.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...