none
System.Security.Cryptography.CryptographicException: 密钥集不存在 怎么解决??? RRS feed

  • 问题

  • “/WCFServer”应用程序中的服务器错误。

    密钥集不存在。

    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 

    异常详细信息: System.Security.Cryptography.CryptographicException: 密钥集不存在。


    源错误: 

    执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

    堆栈跟踪: 

    [CryptographicException: 密钥集不存在。
    ]
      System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) +7710462
      System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle) +67
      System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() +83
      System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize) +226
      System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) +9
      System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey() +202
      System.ServiceModel.Security.SecurityUtils.EnsureCertificateCanDoKeyExchange(X509Certificate2 certificate) +69
    
    [ArgumentException: 证书“CN=MyServerCert”必须具有能够进行密钥交换的私钥。该进程必须具有访问私钥的权限。]
      System.ServiceModel.Security.SecurityUtils.EnsureCertificateCanDoKeyExchange(X509Certificate2 certificate) +11590330
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateServerX509TokenProvider() +36
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateLocalSecurityTokenProvider(RecipientServiceModelSecurityTokenRequirement recipientRequirement) +63
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateSecurityTokenProvider(SecurityTokenRequirement requirement) +54
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateTlsnegoServerX509TokenProvider(RecipientServiceModelSecurityTokenRequirement recipientRequirement) +140
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateTlsnegoSecurityTokenAuthenticator(RecipientServiceModelSecurityTokenRequirement recipientRequirement, Boolean requireClientCertificate, SecurityTokenResolver& sctResolver) +466
      System.ServiceModel.Security.ServiceCredentialsSecurityTokenManager.CreateSecurityTokenAuthenticator(SecurityTokenRequirement tokenRequirement, SecurityTokenResolver& outOfBandTokenResolver) +619
      System.ServiceModel.Security.SessionRenewSecurityTokenManager.CreateSecurityTokenAuthenticator(SecurityTokenRequirement tokenRequirement, SecurityTokenResolver& outOfBandTokenResolver) +85
      System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan timeout) +11294551
      System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +21
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Security.SecurityProtocolFactory.Open(Boolean actAsInitiator, TimeSpan timeout) +23
      System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout) +80
      System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout) +204
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +72
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +107
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan timeout) +129
      System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +21
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan timeout) +20
      System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequired(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout) +34
      System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan timeout) +664
      System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) +21
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout) +133
      System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout) +204
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +72
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +107
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +261
      System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +121
      System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
    
    [ServiceActivationException: 由于编译过程中出现异常,无法激活服务“/WCFServer/Service1.svc”。异常消息为: 证书“CN=MyServerCert”必须具有能够进行密钥交换的私钥。该进程必须具有访问私钥的权限。。]
      System.ServiceModel.AsyncResult.End(IAsyncResult result) +11527290
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
      System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +23
      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    


    版本信息: Microsoft .NET Framework 版本:2.0.50727.3053; ASP.NET 版本:2.0.50727.3053
    2011年8月21日 2:50

答案

  • 使用FindPrivateKey工具找到你的证书,手动也能查找到,在User目录下的某个目录的下有个CrypTo的目录,这里面挨个挨个看文件的更新时间,然后回忆你制作证书的时间,找到匹配的文件,

    然后在文件上赋予asp.net帐户的访问权限,通常是把Network Service帐号加上,设置为"读取"

    2011年8月24日 14:57

全部回复