加密重要信息,如用戶名、密碼。防止http攔截。瀏覽器使用公鑰加密,服務器端使用私鑰解密
頁面添加引用: jsencrypt.min.js
// 3-Url參數加密類 if (window.JSEncrypt) { function InitJSEncrypt() { var _this = this; var encrypt; _this.init = function () { encrypt = new window.JSEncrypt(); encrypt.setPublicKey('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');//替換公鑰 }; _this.getEncrypt = function () { if (encrypt == null) { _this.init(); } return encrypt; }; }; $.extend(window.JSEncrypt, new InitJSEncrypt().getEncrypt()); }
//加密用戶名密碼
var encryptedEmail = window.JSEncrypt.encrypt(email); var encryptedPass = window.JSEncrypt.encrypt(password);