程序开发 > C# > 正文

解决rsa拒绝访问 CreateProvHandle

亮术网 2014-08-15 本网原创

  .Net 开发的网站,配置文件(Web.config)中的敏感重要信息通常都需要加密,以确保它们的安全。但加密之后问题也随之而来,在服务器上架设网站时常遇到“发生了未经处理的异常,ras拒绝访问”;错误提示信息虽然十分详细,但没有说明是那里(哪个文件或文件夹)拒绝访问(错误信息只能看出是 ras加密被拒绝访问),一时半会让人无从下手。

  “发生了未经处理的异常,ras拒绝访问”是在 Windows 的事件查看器中显示的,先看错误的详细信息

事件代码: 3005
事件消息: 发生了未经处理的异常。
事件时间: 2014-7-24 17:38:15
事件时间(UTC): 2014-7-24 9:38:15
事件 ID: dfad62d94ee44e4eb4b0433ec5912fdf
事件序列: 6
事件匹配项: 1
事件详细信息代码: 0

应用程序信息:
    应用程序域: /LM/W3SVC/782733/Root-4-130506682930059681
    信任级别: Full
    应用程序虚拟路径: /
    应用程序路径: E:\web\rui\
    计算机名: CLOUD

 
进程信息:
    进程 ID: 1632
    进程名: w3wp.exe
    帐户名: NT AUTHORITY\NETWORK SERVICE

 
异常信息:
    异常类型: CryptographicException
    异常消息: 拒绝访问。


   在 System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   在 System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
   在 System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
   在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters)
   在 LS.Security.RSACrypto.InitCrypto(String containerName)
   在 lisiya.md.ms.ManageLogin.Page_Load(Object sender, EventArgs e)
   在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   在 System.Web.UI.Control.OnLoad(EventArgs e)
   在 System.Web.UI.Control.LoadRecursive()
   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 
 
请求信息:
    请求 URL: http://www .xxx .com/mu/Login.aspx
    请求路径: /mu/Login.aspx
    用户主机地址: 125.203.141.149
    用户: 
    是否已经过身份验证: False
    身份验证类型: 
    线程帐户名: NT AUTHORITY\NETWORK SERVICE
 
线程信息:
    线程 ID: 10
    线程帐户名: NT AUTHORITY\NETWORK SERVICE
    是否正在模拟: False
    堆栈跟踪:    在 System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
   在 System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
   在 System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
   在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
   在 System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters)
   在 LS.Security.RSACrypto.InitCrypto(String containerName)
   在 lisiya.md.ms.ManageLogin.Page_Load(Object sender, EventArgs e)
   在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   在 System.Web.UI.Control.OnLoad(EventArgs e)
   在 System.Web.UI.Control.LoadRecursive()
   在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
 

 

  错误信息可知道的关键信息:

  1、访问哪个网页文件出错(Login.aspx);

  2、进程名为 w3wp.exe 和 帐户名为 NT AUTHORITY\NETWORK SERVICE;

  3、从“堆栈跟踪”可以看出是 rsa加密出错。

 

 

  rsa拒绝访问解决方法:

  1、给 C:\Documents and Settings\All Users 目录下的 Application Data 文件夹添加 NETWORK SERVICE 用户,并分配“读取”权限。经过此操作,上述问题就能解决。


  2、ras加密还需要一处权限,即给 C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA 目录下的 MachineKeys 文件夹分配“修改和读取”权限;一般往 MachineKeys 文件夹中写密钥时需要“修改”权限,写完之后只留“读取”权限就行了。

本文浓缩标签:rsa拒绝访问加密