Reprint: http://www.cnblogs.com/jys509/p/4499978.html
When invoking the RSA encrypted. PFX key, there is no problem with local debugging, and the following error is reported when the server is ready for deployment:
The user code did not process System.Security.Cryptography.CryptographicException hresult=-2146893792 message= An internal error occurred. Source=mscorlib StackTrace: In System.Security.Cryptography.CryptographicException.ThrowCryptographicException ( Int32 hr) in System.security.cryptography.x509certificates.x509utils._loadcertfromfile (String fileName, IntPtr passwo Rd, UInt32 DwFlags, Boolean persistkeyset, safecertcontexthandle& pcertctx) in System.Security.Cryptography.X509C Ertificates. X509certificate.loadcertificatefromfile (String fileName, Object password, x509keystorageflags keystorageflags) in Sys Tem. Security.Cryptography.X509Certificates.X509Certificate2. ctor (String fileName, string password, x509keystorageflags keystorageflags) in xxxxx. Api. Tools.RSA.Sign (String data, String KeyPath, String keypasswd) is in xxxxx. Api. Tools.Encrypt.signANDencrypt (Msgbean Req_bean) in xxxxx. API.xxxxx.GetBankCardInfo (String orderId, String Cardno) is in xxxxx. Getbankcardinfo (Getbankcardinforeq request) position D:\app_service\WHTR_SOA\WHTR. Soa. Services\onlinepay\yilian\onlinepayservice.cs: Line number 108 in Castle.Proxies.Invocations.xxxxx.InvokeMethodOnTarget () In Castle.DynamicProxy.AbstractInvocation.Proceed () in xxxxx. Castlemethodinvocation.proceed () position D:\xxxxx.cs: line number 80 in xxxxx. Intercept (imethodinvocation invocation) Location D:\xxxxx.cs: line number: innerexception
Processing method:
IIS Application Pool--Select the configured application pool for your site--right-click on Advanced Configuration--Set load user profile to True. Problem solving
3. If none of the above two scenarios solve the problem, it is possible that the certificate was not given a certificate store identity when it was loaded
Workaround: Use the following method when loading the certificate method, note the third parameter
X509Certificate2 cer = new X509Certificate2 (cerpath, password, x509keystorageflags.machinekeyset | X509keystorageflags.persistkeyset | X509keystorageflags.exportable);
Req. Clientcertificates.add (CER);
User code unhandled System.Security.Cryptography.CryptographicException error resolution occurs when deploying