System.Security.Cryptography.CryptographicException: 系统找不到指定的文件
来源:互联网 发布:php就业发展前景 编辑:程序博客网 时间:2024/06/01 20:27
最近,研究RSA加密解密时,出现一个Bug。
是这样的,在远程测试接口时,需要进行RSA数据解密。
RSA解密代码如下:
/// <summary> /// RSA解密 /// </summary> /// <param name="encryptData">经过Base64编码的密文</param> /// <param name="privateKey">私钥</param> /// <returns>RSA解密后的数据</returns> public static string decrypt(string encryptData, string privateKey) { string decryptData = ""; try { RSACryptoServiceProvider provider = new RSACryptoServiceProvider(); provider.FromXmlString(privateKey); byte[] bEncrypt = Convert.FromBase64String(encryptData); int length = bEncrypt.Length; int offset = 0; string cache ; int i = 0; while (length - offset > 0) { if (length - offset > MAXDECRYPTSIZE) { cache = Encoding.UTF8.GetString(provider.Decrypt(getSplit(bEncrypt, offset, MAXDECRYPTSIZE), false)); } else { cache = Encoding.UTF8.GetString(provider.Decrypt(getSplit(bEncrypt, offset, length - offset), false)); } decryptData += cache; i++; offset = i*MAXDECRYPTSIZE; } } catch(Exception e) { throw e; } return decryptData; }
在进行本地调试或者是发布到本地IIS上,加密解密一切正常,但是,一把服务发布到远程服务器上时,在进行解密,却提示如下错误:
System.Security.Cryptography.CryptographicException:系统找不到指定的文件。
在 Util.Security.RSAUtils.decrypt(String encryptData,String privateKey) 位置 D:\documents\visual studio2010\Projects\MSPJK\MSPJK\RSAUtils.cs:行号 175
在MSPJK.DAO.DAO.login(loginInfo loginInfo) 位置 D:\documents\visualstudio 2010\Projects\MSPJK\MSPJK\DAO.cs:行号 2052
在找了许多资料后算是解决了。解决办法如下:
将代码中:
RSACryptoServiceProvider provider = new RSACryptoServiceProvider();
改为:
CspParameters RSAParams = new CspParameters();
RSAParams.Flags = CspProviderFlags.UseMachineKeyStore;
System.Security.Cryptography.RSACryptoServiceProvider provider = new RSACryptoServiceProvider(1024, RSAParams);
再进行测试,OK了!
参考:http://www.verydemo.com/cm.jsp?c=66&u=systemsecuritycryptographycryptographicexception-xi-tong-zhao-bu-dao-zhi-ding-de-wen-jian-jie-jue-ban-fa-zhuan
- System.Security.Cryptography.CryptographicException: 系统找不到指定的文件。
- System.Security.Cryptography.CryptographicException: 系统找不到指定的文件
- C# System.Security.Cryptography.CryptographicException: 系统找不到指定的路径。
- 开发微信发红包时,本地测试没有问题发布IIS上提示 System.Security.Cryptography.CryptographicException: 系统找不到指定的文件。
- System.Security.Cryptography.CryptographicException
- .NET:System.Security.Cryptography.CryptographicException 的解决办法
- DotNetNuke: System.Security.Cryptography.CryptographicException: Bad Data
- System.Security.Cryptography.CryptographicException: 密钥集不存在。
- 获取证书私钥 报“System.Security.Cryptography.CryptographicException”类型的异常
- 部署时System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
- System.Security.Cryptography实战
- System.Security.Cryptography加密。
- System.Security.Cryptography
- 系统找不到指定的文件
- 系统找不到指定的文件
- 系统找不到指定的文件
- system.data.sqlclient.sqlerror 出现操作系统错误2 系统找不到指定的文件
- System.Security.Cryptography C# 加密和解密的学习
- CoordinateMatrix To IndexedRowMatrix or To RowMatrix then SVD
- 科普文之iis写权限漏洞
- 一、pairs vs ipairs
- Ubuntu的命令及设置等
- android- Button点击与监听器处理
- System.Security.Cryptography.CryptographicException: 系统找不到指定的文件
- 平年闰年示意图
- 八爪鱼大数据应用技能培训课程开始报名啦!
- gnuradio的安装问题
- hdu 1272小希的迷宫 并查集
- 高性能 mysql架构与历史
- HDU 1099 Lottery (数学问题模拟)
- FFmpeg深入分析之零-基础
- Linux 安装C++ HTTP JSON客户端