項目要實現請求參數加密 javascript
1.aes.js引入java
<!--加密方法AES+ECB模式--> <script type="text/javascript" src="components/util/aes.js"></script>
2.加密解密方法調用加密
// AES加密方法,encrypt:要加密的數據 function aesEncrypt (encrypt) { var aesPrivateKey = '1234567890123456';//密鑰 var key = CryptoJS.enc.Utf8.parse(aesPrivateKey); var srcs = CryptoJS.enc.Utf8.parse(JSON.stringify(encrypt)); var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7}); return encrypted.toString(); } // AES 解密方法 function aesDecrypt (decryptString) { var aesPrivateKey = '1234567890123456';//密鑰 var key = CryptoJS.enc.Utf8.parse(aesPrivateKey); var decrypt = CryptoJS.AES.decrypt(decryptString, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7}); return CryptoJS.enc.Utf8.stringify(decrypt).toString(); } //如何調用?舉例 var data1 = {yhbh:'2018048'}; var AES = aesEncrypt(data1); console.log(AES);//klOJHhgVNMS1fyvMv/AWZVvvlIl5yWe26nXZSEFU6Bc= var AFTERAES = aesDecrypt(AES); console.log(AFTERAES);//{yhbh:'2018048'};
搞定~spa