【发布时间】:2017-08-04 10:00:16
【问题描述】:
我在我的 mvc 项目中使用https://github.com/jrnker/CSharp-easy-RSA-PEM 实现 RSA。
它在 IIS 和 Visual Studio 中的本地机器上运行良好,但是当我在服务器上部署我的应用程序时,它给了我以下异常。
"System.NullReferenceException: Object reference not set to an instance of an object.\r\n at CoreEntities.Classes.Utility.RSADecrypt(String input)\r\n at WebAPI.Attributes.ApiAuthorizeAttribute.Authorize(HttpActionContext actionContext)"
我的代码是:
public static string RSADecrypt(string input)
{
try
{
string priv = File.ReadAllText(HostingEnvironment.MapPath("~/Certificates/consumer.pem"));
RSACryptoServiceProvider privc = Crypto.DecodeRsaPrivateKey(priv);
return Crypto.DecryptString(input, privc);
}
catch (Exception ex)
{
throw ex;
}
}
我也在 github 上发布了我的问题 @https://github.com/jrnker/CSharp-easy-RSA-PEM/issues/8
经过大量调试,我发现系统没有创建RSACryptoServiceProvider的对象
CspParameters parms = new CspParameters();
parms.Flags = CspProviderFlags.NoFlags;
parms.KeyContainerName = Guid.NewGuid().ToString().ToUpperInvariant();
parms.ProviderType = ((Environment.OSVersion.Version.Major > 5) || ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor >= 1))) ? 0x18 : 1;
// Exception is comping in below line.
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(parms);
RSAParameters rsAparams = new RSAParameters();
例外:- System.Security.Cryptography.CryptographicException: The system cannot find the file specified.\r\n\r\n at CoreEntities.Classes.Utility.RSADecrypt(String input)\r\n at WebAPI.Attributes.ApiAuthorizeAttribute.Authorize(HttpActionContext actionContext)
谁能帮忙...
【问题讨论】:
标签: c# .net asp.net-mvc encryption rsa