crypto-js实现浏览器端AES二进制数据对称加密解密示例代码

代码语言:html

所属分类:其他

代码描述:crypto-js实现浏览器端AES二进制数据对称加密解密示例代码

代码标签: crypto-js 浏览器 AES 二进制 对称 加密 解密 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
  
</head>
<body>

<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/crypto-js.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/aes.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/mode-cfb.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/pad-nopadding.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/lib-typedarrays.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/enc-base64.js"></script>
<script src="//repo.bfw.wiki/bfwrepo/js/crypto-js.4.1.1/enc-u8array.js"></script>
<script>
     
// 服务端提供的32位key
var akey = [0x26,0xAF,0xE2,0x1A,0x0C,0x16,0x73,0x54,0x13,0xFD,0x68,0xDD,0x8F,0xA0,0xB7,0xC1,0x57,0xA6,0x90,0xFF,0xCD,0xB3,0x54,0x61,0x10,0x07,0xD5,0x7E,0xDB,0x1E,0x4C,0xE9];
// 服务端提供的16位iv
var aiv = [0x15,0x4C,0xD3,0x55,0xFE,0xA1,0xFF,0x01,0x00,0x34,0xAB,0x22,0x08,0x4F,0x13,0x07];
 
// 将key和iv转换成uint8数组
var keyBv = new Uint8Array(akey);
var ivBv = new Uint8Array(aiv);
 
// 将key和iv转换成WordArray
keyWA = CryptoJS.enc.u8array.parse(keyBv);
ivWA = CryptoJS.enc.u8array.parse(ivBv);
 
// 解密方法 传入密文的uint.........完整代码请登录后点击上方下载按钮下载查看

网友评论0