【Azure 应用服务】在App Service中调用外部服务API时需要携带客户端证书,而多次调用的情况下会出现WindowsCryptographicException Keyset does not exist异常
2022-03-23 21:00
891 查看
问题描述
在App Service中调用外部服务API时需要携带客户端证书,而多次调用的情况下会出现WindowsCryptographicException Keyset does not exist异常。
错误Tarce:
Exception: Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist at Internal.NativeCrypto.CapiHelper.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer) at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeProvHandle() at System.Security.Cryptography.RSACryptoServiceProvider.get_SafeKeyHandle() at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 keySize, CspParameters parameters, Boolean useDefaultKeySize) at System.Security.Cryptography.RSACryptoServiceProvider..ctor(CspParameters parameters) at Internal.Cryptography.Pal.CertificatePal.<>c.<GetRSAPrivateKey>b__66_0(CspParameters csp) at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng) at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey() at Internal.Cryptography.Pal.CertificateExtensionsCommon.GetPrivateKey[T](X509Certificate2 certificate, Predicate`1 matchesConstraints) at xxxxxxxx.Paylink.WeChatPay.WeChatPayOptions.GetCertificateInfo()
问题分析
当在App Service中上传证书后,可以通过Kudu站点来查看证书是否存在。在Currentuser\My目录下则使用以下PowerShell指令:
Get-ChildItem Cert:\currentuser\My\
通过PowerShell命令查看证书是否存在,并没有能解决App Service中的 “WindowsCryptographicException Keyset does not exist” 问题,只是说从侧面证明当前实例中是否有证书。如果没有,那么错误非常明显,就需要在实例中安装证书。
但是如果证书还是存在,而错误情况依旧,通过多次验证发现于启用了App Service多实例有关。 虽然没有证明为什么在多实例的情况下出现证书获取不到的情况,但是当使用App Service单实例后,问题不在发生。
个人猜想:是否时在代码中加载证书时候的代码在多实例的情况下,某一个实例出现没有加载到证书的情况而导致。
PS: 记录App Service上出现的证书问题,以待未来再次遇见而参考。有新的发现在更新博文。
For more details, you could refer to the links below.
相关文章推荐
- 【Azure 应用服务】应用代码需要客户端证书进行验证,部署到App Service后,如何配置让客户端携带证书呢?
- 【Azure 应用服务】App Service 配置 Application Settings 访问Storage Account得到 could not be resolved: '*.file.core.windows.net'的报错。没有解析成对应中国区 Storage Account地址 *.file.core.chinacloudapi.cn
- 【Azure 应用服务】在Azure App Service for Windows 中部署Java/NodeJS/Python项目时,web.config的配置模板内容
- 【Azure 应用服务】Azure App Service (Windows) 使用Flask框架部署Python应用,如何在代码中访问静态文件呢?如何设置文件路径?是相对路径还是绝对路径呢?
- 【Azure 环境】使用Azure中的App Service部署Web应用,以Windows为主机系统是否可以启动防病毒,防恶意软件服务呢(Microsoft Antimalware)?
- Common problem with SharePoint 2010: System.Security.Cryptography.CryptographicException - Keyset does not exist(转)
- 【Azure 应用服务】App Service 无法连接到Azure MySQL服务,报错:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- 【Azure 应用服务】App Service / Function App 修改系统时区为中国时区的办法(Azure中所有服务的默认时间都为UTC时间,转换为北京时间需要+8小时)
- WCF分布式开发常见错误(3):客户端调用服务出错:You have tried to create a channel to a service that does not support .Net Framing
- 【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found
- System.Security.Cryptography.CryptographicException: Keyset does not exist or Access is denied.
- 【Azure 应用服务】App Service For Windows 中如何设置代理实现前端静态文件和后端Java Spring Boot Jar包
- Caused by: org.jbpm.api.JbpmException: resource jbpm.cfg.xml does not exist
- 【Azure 应用服务】App Service For Linux 部署PHP Laravel 项目,如何修改首页路径为 wwwroot\public\index.php
- Tomcat的异常 之 java.lang.IllegalArgumentException: Document base *** does not exist or is not a readable
- 【Azure 应用服务】Azure App Service能否使用Storage Account File Share
- 【Azure 应用服务】App Service"访问控制/流量监控"四问
- 【Azure 应用服务】App Service 进入后台管理(Kudu)页面,因为文件过多而显示不全的问题
- 【Azure Spring Cloud】使用azure-spring-boot-starter-storage来上传文件报错: java.net.UnknownHostException: xxxxxxxx.blob.core.windows.net: Name or service not known
- 【Azure 应用服务】App Service与Application Gateway组合使用时发生的域名跳转问题如何解决呢?