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