注意几点:

  1、参数传递的+号处理,在传输时会把+变成空格,不处理后端就报错了。

1、前端代码

<!DOCTYPE html>

<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <title>Login</title>
 <script src="/UploadFiles/2021-04-02/jquery-1.10.2.min.js">

2、后端代码

 

public class IndexController : Controller
 {  public ActionResult Login()
  {
   return View();
  }
  [HttpPost]
  public ActionResult Login(string pwd)
  {
   //密钥格式要生成pkcs#1格式的 而不是pkcs#8格式的
   string privateKey = @"MIICWwIBAAKBgQCa4KHNwDX44gGmmIAtRu4gjVYtGWZzcm4t+1wjUD4dn7fMLPvuK7ai4UrfDeEJE1RPwudJw+lJ6crql8wSIg7/DbTlG3ihsCT6dT9H5B9OoeR7K9VW
UesaW/iyVL6HXiYOANabW14pvJATDmdq91Tfgp6PSQyvdfiRdV4r07crpQIDAQAB
AoGABb+3gdb+qeG0b1CogVsT/7//UOaTzPk/FGneKQQTf4SsN+H7lVhTYTG9ARFC
JyoWg8IXqmn2ljhywHPTWWD2RCZIn2sYT1sVkGb70EgHGQLBraFHElmw+DsVJ+nD
fBCfMrJ1TYXlwigjRkaueaoGgG8LdR8XD+Xs5LersPLjZgECQQCguSB7C4wF6oSw
EDmwNF8ffT5cQc1U2OIq6NBG8rafrjb7LsjhOd03pmY7i4LbW3Vvq4AhQpJEdF1C
vd+Sk/BBAkEA9rBhqnyumV09zFEomSX3zZu+bdhTzM4bJDfEa95swp1gANCVvF/t
DCnlBf51EhCWdeGSpARPUkQnXrYfFUDiZQJAAZEshuaa6+fYeVr/JP+tucHf3Mhr
dxtSQTbZ6QcuzqnFMXfIT6HfzU4bCxOWKAthPsB+VFSw1mgIDMGLL4OvwQJAJlVy
V9PYLezXVZCnBmVoBINXLCqZmxHMFey0kS6XKAbcjEPdgNBHPcSk2jGYb540Q00y
RFqHGPmORKF4Yw0aIQJAd5JRtD3z2MgP/vPoKHJNHqY8bboVcmwqVAm6xCZoTCZz
jNV1Cnsdf4wBV3LCDzYBy+xR4qYNUy5CFXN+8WzzAA==";
   try
   {
    RSACryptoServiceProvider rsaCryptoServiceProvider = CreateRsaProviderFromPrivateKey(privateKey);
    //把+号,再替换回来
    byte[] res = rsaCryptoServiceProvider.Decrypt(Convert.FromBase64String(pwd.Replace("%2B","+")), false);
    return Content(Encoding.UTF8.GetString(res));
   }
   catch (Exception exception)
   {
   }
   return Content("");
  }
  private RSACryptoServiceProvider CreateRsaProviderFromPrivateKey(string privateKey)
  {
   var privateKeyBits = System.Convert.FromBase64String(privateKey);

   var RSA = new RSACryptoServiceProvider();
   var RSAparams = new RSAParameters();

   using (BinaryReader binr = new BinaryReader(new MemoryStream(privateKeyBits)))
   {
    byte bt = 0;
    ushort twobytes = 0;
    twobytes = binr.ReadUInt16();
    if (twobytes == 0x8130)
     binr.ReadByte();
    else if (twobytes == 0x8230)
     binr.ReadInt16();
    else
     throw new Exception("Unexpected value read binr.ReadUInt16()");

    twobytes = binr.ReadUInt16();
    if (twobytes != 0x0102)
     throw new Exception("Unexpected version");

    bt = binr.ReadByte();
    if (bt != 0x00)
     throw new Exception("Unexpected value read binr.ReadByte()");

    RSAparams.Modulus = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.Exponent = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.D = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.P = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.Q = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.DP = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.DQ = binr.ReadBytes(GetIntegerSize(binr));
    RSAparams.InverseQ = binr.ReadBytes(GetIntegerSize(binr));
   }

   RSA.ImportParameters(RSAparams);
   return RSA;
  }
  private int GetIntegerSize(BinaryReader binr)
  {
   byte bt = 0;
   byte lowbyte = 0x00;
   byte highbyte = 0x00;
   int count = 0;
   bt = binr.ReadByte();
   if (bt != 0x02)
    return 0;
   bt = binr.ReadByte();

   if (bt == 0x81)
    count = binr.ReadByte();
   else
    if (bt == 0x82)
    {
     highbyte = binr.ReadByte();
     lowbyte = binr.ReadByte();
     byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
     count = BitConverter.ToInt32(modint, 0);
    }
    else
    {
     count = bt;
    }

   while (binr.ReadByte() == 0x00)
   {
    count -= 1;
   }
   binr.BaseStream.Seek(-1, SeekOrigin.Current);
   return count;
  }
 }

总结

以上所述是小编给大家介绍的Js参数RSA加密传输之jsencrypt.js的使用,希望对大家有所帮助!

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。