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);
posted @ 2019-11-24 11:09  .Neterr  阅读(2403)  评论(0编辑  收藏  举报