转载: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. Hybris电商方案介绍(企业全渠道) B2B B2C O2O建设

    1). 什么是Hybris: hybris software成立于1997年,2013年与SAP整合,成为SAP旗下的一份子,提供全渠道客户互动与商务解决方案,该解决方案能够为各机构提供客户的实时背景 ...

  2. MySql 数据操作类

    /// <summary> /// MySqlHelper 的摘要说明. /// </summary> public class MySqlHelper { public st ...

  3. 算法导论第十八章 B树

    一.高级数据结构 本章以后到第21章(并查集)隶属于高级数据结构的内容.前面还留了两章:贪心算法和摊还分析,打算后面再来补充.之前的章节讨论的支持动态数据集上的操作,如查找.插入.删除等都是基于简单的 ...

  4. 个性化EDM数据营销的三大提醒

    EDM数据营销行业已经进入个性化时代.但是怎样实现个性化仍然是一个重大课题.国内领先的智能化邮件营销服务商Focussend一直致力于探索和研究邮件营销领域的先进知识和做法,旨在为企业和个人提供更多有 ...

  5. 六款值得推荐的android(安卓)开源框架

    1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1)  JSON,图像等的异步下载: (2)  网络请求的排序(scheduli ...

  6. main函数读取jar包外部的配置文件properties

    首先,Java的main方法有个初始化入参args,如下所示: public static void main(String[] args) {} 然后,在linux下执行jar包引入外部配置文件的命 ...

  7. SmartJS 第一期(0.1)发布 - AOP三剑客

    隔了好久才终于又发布了一点东西,SmartJS是最近才开始搞的一个开源js库,目的是做一些比较有特点的事情(smartjs暂时也是依赖于jquery). SmartJS的内容规划比较多,也无法在短时间 ...

  8. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  9. css的两种引用方式 link和@import

    学习web开发的最大乐趣就是不断的发现自己以前不曾见过的东西,这些东西对于我来说是那么的新鲜有趣. 比如说今天偶尔研究别人的网站,就发现了有趣的东东. 当点开此网页的css时(这个css文件命名方式就 ...

  10. MongoDB的学习--文档的查询

    继续关于<MongoDB权威指南>记录,今天的内容是文档的查询~~ MongoDB官网地址:http://www.mongodb.org/ 我使用的是MongoDB 2.4.8 find函 ...