User code unhandled System.Security.Cryptography.CryptographicException error resolution occurs when deploying

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.