[英]Creating Certificate from base64 encoded string failing in Azure Function
I am trying to create an X509Certificate2
from a base64 encoded string.我正在尝试从 base64 编码字符串创建X509Certificate2
。 This code I have added to a sample Azure function.我已将此代码添加到示例 Azure function 中。 Locally the code works and I can create a cerificate object from bas364 encoded string, however when publishing to Azure I get an exception在本地代码有效,我可以从 bas364 编码字符串创建证书 object,但是在发布到 Azure 时出现异常Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore
Following https://github.com/dotnet/runtime/issues/30658 I have kept app service plan as '(P1v2: 1)' which is not shared. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException at Internal.Cryptography.Pal.CertificatePal.FilterPFXStore
遵循https://github.com/dotnet/runtime/issues/30658我将应用服务计划保留为“(P1v2:1)”,这不是共享。
Use WEBSITE_LOAD_CERTIFICATES
app setting in your azure function the specified certificates accessible to your Windows hosted app in the Windows certificate store, in Current_User\Your_user . Use WEBSITE_LOAD_CERTIFICATES
app setting in your azure function the specified certificates accessible to your Windows hosted app in the Windows certificate store, in Current_User\Your_user .
In your code, access the certificate by the certificate thumbprint.在您的代码中,通过证书指纹访问证书。 Like certificateThumbprint = "<your certificate thumbprint>";
像certificateThumbprint = "<your certificate thumbprint>";
Note: App Service inject the certificate paths into Windows containers.注意:应用服务将证书路径注入 Windows 容器。 like variables
WEBSITE_PRIVATE_CERTS_PATH
,WEBSITE_INTERMEDIATE_CERTS_PATH
,WEBSITE_PUBLIC_CERTS_PATH
, andWEBSITE_ROOT_CERTS_PATH
.像变量WEBSITE_PRIVATE_CERTS_PATH
、WEBSITE_INTERMEDIATE_CERTS_PATH
、WEBSITE_PUBLIC_CERTS_PATH
和WEBSITE_ROOT_CERTS_PATH
。 Make sure you have to reference the certificate path with the environment variables instead of hardcoding the certificate path.确保您必须使用环境变量引用证书路径,而不是对证书路径进行硬编码。
If still, you are facing the same issue you can add the WEBSITE_LOAD_USER_PROFILE=1
app settings in your app.如果仍然存在,您也面临同样的问题,您可以在您的应用中添加WEBSITE_LOAD_USER_PROFILE=1
应用设置。 The error says that the certificate not accessible for specific user.该错误表示特定用户无法访问该证书。 It will fix your problem.它将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.