JS中使用RSA加密信息


加密重要信息,如用戶名、密碼。防止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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM