javascript进⾏aes加密、解密
//该⽅法可与Java进⾏相互加解密<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>需要秘钥(key)及秘钥偏移量(iv)的aes加解密</title>
</head>
<body>
<script src="aes_1.js"></script>  //引⼊的js⽂件在该链接中:
<script>
var key = Utf8.parse("⼗六位⼗六进制数作为秘钥");
var iv = Utf8.parse('⼗六位⼗六进制数作为秘钥偏移量');
function Encrypt(word){
srcs = Utf8.parse(word);
var encrypted = pt(srcs, key, { iv: iv,de.CBC,padding: CryptoJS.pad.Pkcs7}); return String().toUpperCase();
}
function Decrypt(word){
var encryptedHexStr = Hex.parse(word);
var srcs = Base64.stringify(encryptedHexStr);
var decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv,de.CBC,padding: CryptoJS.pad.Pkcs7}); var decryptedStr = Utf8);
String();
}
var mm = Encrypt('nihao')
console.log(mm);
var jm = Decrypt(mm);
console.log(jm)
</script>
</body>
</html>//如果想要深度了解每步作⽤,可以参考:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>加解密时仅需要秘钥</title>
</head>
<body>
<script src="aes_2.js"></script>  //引⼊的js⽂件在该链接中:
<script type="text/javascript">
如何下载javascriptvar pwd="秘钥";
function Encrypt(word){
return pt(word,pwd).toString();
}
function Decrypt(word){
return CryptoJS.AES.decrypt(word,pwd).Utf8);
}
var mm = Encrypt('nihao');
console.log(mm)
var jm = Decrypt(mm);
console.log(jm)
</script> </body> </html>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。