[英]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:这是同一问题的解决方法:
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.