转载: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. 精选29款非常实用的jQuery应用插件

    今天我们来分享一些实用的jQuery应用插件,没有特别花哨,但都比较实用,jQuery菜单.jQuery图片都有涉及到,一起来看看. 1.jQuery+CSS3仿IOS无线局域网Wifi DEMO演示 ...

  2. 【特别推荐】8个富有创意的jQuery/CSS3插件

    现在的互联网上什么都有,但是真正好的创意却非常稀缺,包括WEB界面也是如此,今天我们要特别推荐8个富有创意的jQuery/CSS3插件,也许这几个插件能让你的WEB界面更加富有创意和人性化. 1.jQ ...

  3. IoC控制反转与DI依赖注入

    IoC控制反转与DI依赖注入 IoC: Inversion of Control IoC是一种模式.目的是达到程序的复用.下面的两篇论文是对IoC的权威解释: InversionOfControl h ...

  4. STL中stack小结

    (1)为了运用stack,你必须包含头文件<stack>:#include<stack> (2)在头文件中stack定义如下: namespace std{ template ...

  5. 固态硬盘寿命实测让你直观SSD寿命!--转

    近年来,高端笔记本及系列上网本越来越多的采用固态硬盘来提升整机性能,尽管众所周知固态硬盘除 了在正常的使用中带来更快速度的体验外,还具有零噪音.不怕震动.低功耗等优点,但大家对固态硬盘的寿命问题的担忧 ...

  6. 使用Eclipse调试PHP程序

    我安装的是PHP Version 5.3.26,按照网上提示在Eclipse中使用XDebug进行调试,不过配置了却使用不了,下面把解决方法简要说一下. XDebug老是加载不了 From PHP 5 ...

  7. 服务器唯一id生成规则

    在使用hashCode的时候,发现会出现相同id,虽然几率很小.虽然发现并不是hashCode的原因,而是其他逻辑的问题. 但是还是试着自己写了一个id生成器,有些id是int的,比如说任务id:有些 ...

  8. HT图形组件设计之道(三)

    上篇我们通过定制了CPU和内存展示界面,体验了HT for Web通过定义矢量实现图形绘制与业务数据的代码解耦及绑定联动,这类案例后续文章还会继续以便大家掌握更多的矢量应用场景,本篇我们先切换个话题, ...

  9. 存储过程分页 Ado.Net分页 EF分页 满足90%以上

    存储过程分页: create proc PR_PagerDataByTop @pageIndex int, @pageSize int, @count int out as select top(@p ...

  10. 第一次Sprint总结

    回顾流程      这次我们做(done)的是设计用户登录界面.注册界面.查询功能.链接数据库等,我们成功地把todo变成了done,首先不管我们结果如何,不管我们的付出是否与收获成正比,但我们做到了 ...