RSA加密前端JS加密,后端asp.net解密,报异常

 

参考引用:http://www.ohdave.com/rsa/的JS加密库

前端JS加密代码:

function GetChangeStr() 
{ debugger; var pwdStr = document.getElementById("txtPassWordStr").value; var uidStr= $("#<%=txtUserStr.ClientID%>").val(); if (!pwdStr || pwdStr.length == 0 || !uidStr || uidStr.length==0) { return false; } var keyE = "<%=PubRsaKeyE%>"; var keyM = "<%=PubRsaKeyM%>"; setMaxDigits(131); var key = new RSAKeyPair(keyE, "", keyM); var pwdRtn = encryptedString(key, pwdStr); var uidRtn = encryptedString(key, uidStr); $("#<%=txtPassword.ClientID%>").val(pwdRtn); $("#<%=txtUser.ClientID%>").val(uidRtn); }

后台解密代码:

        try
        {
            RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)Cache.Get("privateKey");
            byte[] result = rsa.Decrypt(HexStringToBytes(password), false);
            password = Encoding.UTF8.GetString(result);

            result = rsa.Decrypt(HexStringToBytes(userName), false);
            userName = Encoding.UTF8.GetString(result);
        }
        catch (Exception ex)
        {
            ShowMessage("身份验证失败!", "您登陆的帐号或密码错误!","");
            return;
        }    

发现在某些研发环境时会报“参数错误”异常。但在其它项目或服务器环境是正常的。

没有找到原因,不明原理啊!!

仅此做个记录。

posted on 2015-12-03 11:05  Mack.Meng  阅读(1304)  评论(1编辑  收藏  举报