zoukankan      html  css  js  c++  java
  • 利用security.js实现RSA加密

    在通常的http协议的网站中直接提交数据可以通过信息抓取从而暴露提交者所提交的信息,特别是注册时的密码和登录时的密码容易被泄露。

    那么怎么防止这种现象呢?

    很多人会想到加密技术,对没错,本文所讲的就是使用rsa非对称加密技术进行数据提交,由客户获取后台所产生的公钥对提交字段进行加密,用户提交后再由后台所产生的私钥进行解密。

    这里以用户登录时对用户密码进行加密为列,下面直接上代码:

    jQuery.ajax({
                    type:"post",
                    url:"loginset",
                    success:function(rd){
                        if(rd!=null){
                            //加密模
                            var Modulus = rd.split(';')[0];
                            //公钥指数
                            var public_exponent = rd.split(';')[1];
                            //通过模和公钥参数获取公钥
                 var key = new RSAUtils.getKeyPair(private_exponent(按道理后台获取), "", Modulus); //颠倒密码的顺序,要不然后解密后会发现密码顺序是反的 var reversedPwd = password.split("").reverse().join(""); //对密码进行加密传输 var encrypedPwd = RSAUtils.encryptedString(key,reversedPwd); jQuery('#subPwd').val(encrypedPwd); jQuery('#loginPwd').val(""); jQuery('#login').submit(); } } }) })

      

     

  • 相关阅读:
    verilog RTL编程实践之四
    TB平台搭建之二
    hdu3466 Proud Merchants
    poj2411 Mondriaan's Dream (用1*2的矩形铺)
    zoj3471 Most Powerful
    poj2923 Relocation
    hdu3001 Travelling
    poj3311 Hie with the Pie
    poj1185 炮兵阵地
    poj3254 Corn Fields
  • 原文地址:https://www.cnblogs.com/jcxfighting/p/10709775.html
Copyright © 2011-2022 走看看