部署时,出现用户代码未处理 System.Security.Cryptography.CryptographicException 错误解决方法...

转载:http://www.cnblogs.com/jys509/p/4499978.html

 

在调用RSA加密的.pfx密钥时,在本地调试没有问题,可以布署到服务器,就会报以下的错误:

用户代码未处理 System.Security.Cryptography.CryptographicException
  HResult=-2146893792
  Message=出现了内部错误。

  Source=mscorlib
  StackTrace:
       在 System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
       在 System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
       在 System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
       在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
       在 xxxxx.API.Tools.RSA.Sign(String data, String keyPath, String keyPasswd)
       在 xxxxx.API.Tools.Encrypt.signANDencrypt(MsgBean req_bean)
       在 xxxxx.API.xxxxx.GetBankCardInfo(String orderId, String cardNo)
       在 xxxxx.GetBankCardInfo(GetBankCardInfoReq request) 位置 d:\app_service\WHTR_SOA\WHTR.SOA.Services\OnlinePay\Yilian\OnlinePayService.cs:行号 108
       在 Castle.Proxies.Invocations.xxxxx.InvokeMethodOnTarget()
       在 Castle.DynamicProxy.AbstractInvocation.Proceed()
       在 xxxxx.CastleMethodInvocation.Proceed() 位置 d:\xxxxx.cs:行号 80
       在 xxxxx.Intercept(IMethodInvocation invocation) 位置 d:\xxxxx.cs:行号 56
  InnerException: 

  

处理方法:

IIS 应用程序池--选中你网站的所配置的应用程序池--右键 选择 “高级配置” --将“加载用户配置文件” 设置为True 。问题解决

 

3.如果以上两个方案都不能解决问题,就有可能是加载证书时没有给定证书存储标识
   

解决方法:在加载证书方法时使用以下方法,请注意第三个参数
    
X509Certificate2 cer = new X509Certificate2(cerPath, password, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); 
req.ClientCertificates.Add(cer);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值