简体   繁体   English

CngKey System.Security.Cryptography.CryptographicException 系统找不到 Azure 上指定的文件

[英]CngKey System.Security.Cryptography.CryptographicException The system cannot find the file specified on Azure

I try to generate key from this code我尝试从此代码生成密钥

CngKey key = CngKey.Import(Convert.FromBase64String(privateKey), CngKeyBlobFormat.Pkcs8PrivateBlob);

it works fine locally but when I deploy in my Azure app service.它在本地运行良好,但是当我在我的 Azure 应用服务中部署时。 it gives me this error:它给了我这个错误:

System.Security.Cryptography.CryptographicException: The system cannot find the file specified. System.Security.Cryptography.CryptographicException:系统找不到指定的文件。 at System.Security.Cryptography.NCryptNative.ImportKey(SafeNCryptProviderHandle provider, Byte[] keyBlob, String format) at System.Security.Cryptography.CngKey.Import(Byte[] keyBlob, String curveName, CngKeyBlobFormat format, CngProvider provider)在 System.Security.Cryptography.NCryptNative.ImportKey(SafeNCryptProviderHandle 提供程序,Byte[] keyBlob,字符串格式)在 System.Security.Cryptography.CngKey.Import(Byte[] keyBlob,字符串曲线名称,CngKeyBlobFormat 格式,CngProvider 提供程序)

I add WEBSITE_LOAD_USER_PROFILE In Configuration with value '1' but it didn't make any difference.我在配置中添加了 WEBSITE_LOAD_USER_PROFILE,值为“1”,但没有任何区别。

Thanks谢谢

If WEBSITE_LOAD_USER_PROFILE = 1 does not work for you.如果WEBSITE_LOAD_USER_PROFILE = 1对您不起作用。 Here is a workaround for this same issue:这是同一问题的解决方法:

  • Open your Azure App Service (Azure Website) blade in portal.azure.com在门户中打开您的 Azure 应用服务(Azure 网站)刀片。azure.com
  • Go to the Application settings page Go 到应用程序设置页面
  • Scroll to App settings滚动到应用设置
  • Add a new entry key: WEBSITE_LOAD_CERTIFICATES, and provide a dummy (fake, made-up, randomly-generated) value for it.添加一个新的条目键:WEBSITE_LOAD_CERTIFICATES,并为其提供一个虚拟(假的、虚构的、随机生成的)值。

Check out the below links for the similar issue for reference:查看以下链接以获取类似问题以供参考:

I upgraded the plan service from free to basic with adding WEBSITE_LOAD_USER_PROFILE = 1 in Azure Configuration.我通过在 Azure 配置中添加 WEBSITE_LOAD_USER_PROFILE = 1 将计划服务从免费升级到基本服务。

The issue was when the app service was free it use a shared VM but when upgrading my app service pricing into basic it use a private VM.问题是当应用服务免费时,它使用共享虚拟机,但是当我的应用服务定价升级到基本时,它使用私有虚拟机。

This issue is not only on Azure, I had the same issue on my VPS as well and this answer save my life:这个问题不仅在 Azure 上,我的 VPS 上也有同样的问题,这个答案挽救了我的生命:

X509Certificate Constructor Exception X509Certificate 构造函数异常

Cheers, Nick干杯,尼克

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Security.Cryptography.CryptographicException:系统找不到指定的文件 - System.Security.Cryptography.CryptographicException: The system cannot find the file specified AppHarbor-System.Security.Cryptography.CryptographicException:系统找不到指定的文件 - AppHarbor - System.Security.Cryptography.CryptographicException: The system cannot find the file specified System.Security.Cryptography.CryptographicException:句柄无效 - System.Security.Cryptography.CryptographicException: The handle is invalid TwilioRequestValidator 中的瞬态 System.Security.Cryptography.CryptographicException - Transient System.Security.Cryptography.CryptographicException in TwilioRequestValidator System.Security.Cryptography.CryptographicException:参数不正确 - System.Security.Cryptography.CryptographicException: The parameter is incorrect SSL TCP SslStream 服务器抛出未处理的异常“System.Security.Cryptography.CryptographicException:找不到原始签名者” - SSL TCP SslStream Server throws unhandled exception “System.Security.Cryptography.CryptographicException: cannot find the original signer” System.Security.Cryptography.CryptographicException:'Cryptography_OAEPDecoding' - System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding' 如何解决System.Security.Cryptography.CryptographicException:指定了无效的提供程序类型 - How to solve System.Security.Cryptography.CryptographicException: Invalid provider type specified System.Security.Cryptography.CryptographicException:RSACryptoserviceProvider中的长度错误 - System.Security.Cryptography.CryptographicException : Bad length in RSACryptoserviceProvider 给出错误密码时出现System.Security.Cryptography.CryptographicException - System.Security.Cryptography.CryptographicException when wrong password given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM