1

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. it gives me this error:

System.Security.Cryptography.CryptographicException: The system cannot find the file specified. 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)

I add WEBSITE_LOAD_USER_PROFILE In Configuration with value '1' but it didn't make any difference.

Thanks

adelahmed
  • 37
  • 3

3 Answers3

3

If WEBSITE_LOAD_USER_PROFILE = 1 does not work for you. Here is a workaround for this same issue:

  • Open your Azure App Service (Azure Website) blade in portal.azure.com
  • Go to the Application settings page
  • Scroll to App settings
  • Add a new entry key: WEBSITE_LOAD_CERTIFICATES, and provide a dummy (fake, made-up, randomly-generated) value for it.

Check out the below links for the similar issue for reference:

Nimantha
  • 5,793
  • 5
  • 23
  • 56
Harshita Singh
  • 4,056
  • 1
  • 8
  • 12
  • the issue was that the app service pricing plan was free when I upgrade it to basic it works fine. Free plan you have a shared VM but start from basic plan you have your own VM – adelahmed Mar 03 '21 at 10:01
0

I upgraded the plan service from free to basic with adding WEBSITE_LOAD_USER_PROFILE = 1 in Azure Configuration.

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.

adelahmed
  • 37
  • 3
0

This issue is not only on Azure, I had the same issue on my VPS as well and this answer save my life:

X509Certificate Constructor Exception

Cheers, Nick

Nick Hoàng
  • 332
  • 1
  • 6