的RSACryptoServiceProvider CryptographicException系统找不到下ASP.NET所指定的文件 [英] RSACryptoServiceProvider CryptographicException System Cannot Find the File Specified under ASP.NET

查看:1538
本文介绍了的RSACryptoServiceProvider CryptographicException系统找不到下ASP.NET所指定的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有正在使用的RSACryptoServiceProvider来使用已知的专用密钥(存储在一个变量)的一些数据进行解密的应用程序。

I have an application which is making use of the RSACryptoServiceProvider to decrypt some data using a known private key (stored in a variable).

在IIS应用程序池配置为使用网络服务,一切都正常运行。

When the IIS Application Pool is configured to use Network Service, everything runs fine.

然而,当我们配置IIS应用程序池,以根据不同的身份运行code,我们得到如下:

However, when we configure the IIS Application Pool to run the code under a different Identity, we get the following:

System.Security.Cryptography.CryptographicException: The system cannot find the file specified.

   at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
   at System.Security.Cryptography.RSA.FromXmlString(String xmlString)

在code是这样的:

The code is something like this:

byte[] input; 
byte[] output; 
string private_key_xml; 

var provider = new System.Cryptography.RSACryptoServiceProvider(this.m_key.Key_Size);
provider.FromXmlString(private_key_xml); // Fails Here when Application Pool Identity != Network Service

ouput = provider.Decrypt(input, false); // False = Use PKCS#1 v1.5 Padding

有它试图通过阐明,你应该给用户读取访问本机密钥存储区来回答它的资源 - 但有没有明确的答案来解决这个问题。

There are resources which attempt to answer it by stating that you should give the user read access to the machine key store - however there is no definitive answer to solve this issue.

环境:IIS 6.0和Windows Server 2003 R2,.NET 3.5 SP1

Environment: IIS 6.0, Windows Server 2003 R2, .NET 3.5 SP1

推荐答案

事实上,你需要工作一个code这样

Indeed you need to work a code like this

CspParameters _cpsParameter;
RSACryptoServiceProvider RSAProvider;

_cpsParameter = new CspParameters();
_cpsParameter.Flags = CspProviderFlags.UseMachineKeyStore;

RSAProvider = new RSACryptoServiceProvider(1024, _cpsParameter);

下面的用户需要访问的文件夹:C:\ Documents和Settings \所有用户\应用数据\微软\加密\ RSA \ MachineKeys的

The following users need access to the folder: C:\Documents and Settings\All Users\Application data\Microsoft\Crypto\RSA\MachineKeys

  1. 在IIS用户帐户(anonymmous)
  2. 您使用假冒您的应用程序在web.config中设置的用户帐户。

所以,现在,它正在对我罚款。

So now it is working fine for me.

这篇关于的RSACryptoServiceProvider CryptographicException系统找不到下ASP.NET所指定的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆