转载: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);

部署时,出现用户代码未处理 System.Security.Cryptography.CryptographicException 错误解决方法的更多相关文章

  1. X509证书 指定了无效的提供程序类型 System.Security.Cryptography.CryptographicException 错误解决方法

    第一种解决办法: IIS 应用程序池--选中你网站的所配置的应用程序池--右键 选择 “高级配置” --将“加载用户配置文件” 设置为True 第二种解决办法: 在加载证书方法时使用以下方法,请注意第 ...

  2. 使用证书部署出现System.Security.Cryptography.CryptographicException 错误解决方案

    一.System.Security.Cryptography.CryptographicException: 找不到对象 at System.Security.Cryptography.Cryptog ...

  3. .NET:System.Security.Cryptography.CryptographicException 的解决办法

    详细内容参考此网址:http://social.msdn.microsoft.com/Forums/en-US/ec93922a-fd1e-4225-b5cf-1472ebb3acd1/systems ...

  4. System.Security.Cryptography.CryptographicException 出现了内部错误

    调试微信支付退款时,需要使用pfx证书,在本地调试时没有问题,但在服务器部署时报异常:System.Security.Cryptography.CryptographicException 出现了内部 ...

  5. WCF:System.Security.Cryptography.CryptographicException: 密钥集不存在

    WCF使用IIS部署时,使用x509证书验证,在创建证书并正确配置程序后,访问出现错误提示: System.Security.Cryptography.CryptographicException: ...

  6. "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法

    .net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...

  7. System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型

    这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...

  8. WebApi 数据保护操作未成功。这可能是由于未为当前线程的用户上下文加载用户配置文件导致的。当线程执行模拟时,可能会出现此情况。","ExceptionType":"System.Security.Cryptography.CryptographicException","StackTrace

    在调用System.Security.Cryptography.ProtectedData.Protect方法来保护私密信息时,IIS可能会报以下错误:CryptographicException: ...

  9. System.Security.Cryptography.CryptographicException

    在调用System.Security.Cryptography.ProtectedData.Protect方法来保护私密信息时,IIS可能会报以下错误:CryptographicException: ...

随机推荐

  1. Android M Permission 学习笔记

    Android应用权限简要介绍 一个Android应用默认情况下是不拥有任何权限的, 这即是说, 在默认情况下, 一个应用是没有权利去进行一些可能会造成不好影响的操作的. 这些不好的影响可能是对其它应 ...

  2. node-sass 安装卡在 node scripts/install.js 解决办法

    转自:https://segmentfault.com/a/1190000005921721 ======== 7月12日更新 ======== 总的来说就是两种方法解决: SASS_BINARY_S ...

  3. Win7“当前用户没有安装Microsoft Office"

    故障:在win7 win10系统已安装office2007~但打开word excel应用程序时提示"当前用户没有安装Microsoft Office". 原因:office200 ...

  4. 最近新装系统windows8.1+Mac。。。还没装驱动就遇到一堆问题。。。

    ---恢复内容开始--- 1,刚开始装好了,后来莫名看不到磁盘了,原因:64位mac盘会丢失盘符,所以macdrive也看不到...解决:(将AF改为06,修改内容后改回AF,早知道这么简单就不用重新 ...

  5. 读书笔记_Effective_C++_条款四十一:了解隐式接口和编译期多态

    从本条款开始,就进入了全书的第七部分:模板与泛型编程.模板与泛型在C++中是非常重要的部分,还记得本书第一章时,把C++视为一个联邦,它由四个州政府组成,其中一个政府就是模板与泛型了. 本条款是一个介 ...

  6. zeromq 测试总结

    总结 测试项目 github (https://github.com/solq360/jmzq) 非常不稳定 pub/sub 模式 30W压测丢了27W条消息,官方没有给出任何的发送状态供业务层处理 ...

  7. MySQL单机load过高问题讨论

    有一个朋友问我: "hi,我想问下你们遇到单机load过高的情况 采取什么紧急措施啊?" 我问他是不是mysql db server? 他说是. 我给他如下建议: 1 先看下是不是 ...

  8. jackson反序列化时忽略不需要的字段

    有时候,如果数据库表中增加一个字段,但返回的JSON字符串中含有我们并不需要的字段,那么当对应的实体类中不含有该字段时,会抛出一个异常,告诉你有些字段没有在实体类中找到.解决办法很简单,在声明Obje ...

  9. HMM 自学教程(七)前向后向算法

    本系列文章摘自 52nlp(我爱自然语言处理: http://www.52nlp.cn/),原文链接在 HMM 学习最佳范例,这是针对 国外网站上一个 HMM 教程 的翻译,作者功底很深,翻译得很精彩 ...

  10. suricata学习笔记1--初步认识

    1.前言  最近工作需要对网站的关键字进行检测,找出敏感词.这个过程需要对报文进行收集.解码.检测和记录日志.当前只是简单实现功能,根据关键字进行简单的匹配,而没有进行关键字的语义分析.导致的结果就是 ...