从 C# Azure 函数中访问证书

Accessing Certificate from within a C# Azure function(从 C# Azure 函数中访问证书)

本文介绍了从 C# Azure 函数中访问证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的 Azure Function 访问证书.

I need to access a certificate from my Azure Function.

我按照 运行时错误加载证书Azure Functions 但没有成功.

I followed the steps outlined in Runtime error loading certificate in Azure Functions but it didn't work out.

private static X509Certificate2 GetCertificate(string thumbprint, TraceWriter log)
{
    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    try
    {
        store.Open(OpenFlags.ReadOnly);
        log.Info("Enumerating certificates");
        foreach (var cert in store.Certificates) {
            log.Info(cert.Subject);
        }
        var col = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
        if (col == null || col.Count == 0)
        {
            return null;
        }
        return col[0];
    }
    finally
    {
        store.Close();
    }

}

上传到 Azure 函数的两个证书和设置 WEBSITE_LOAD_CERTIFICATES 也被添加并设置为 * 或所需证书的 thumpbrint,但无济于事.

Two certificates where uploaded to the Azure Function and the setting WEBSITE_LOAD_CERTIFICATES was added as well and set to either * or to the thumpbrint of the required certificate, but to no avail.

GetCertificate 方法应该打印存储区中所有证书的列表,但存储区是空的.

The GetCertificate method should print a list of all certificates in the store, but the store is empty.

关于如何解决这个问题的任何线索?

Any clues on how to solve this?

推荐答案

更新:消费计划现在支持客户端证书.

UPDATE: Client certificates are now supported in the Consumption plan.

我们的消费计划尚不支持客户端证书,仅在应用服务计划中支持.我们的 repo here 中的一个问题对此进行了跟踪.我们正在努力解决这个问题 - 请关注该问题的状态.谢谢.

Client certificates are not yet supported in our Consumption plan, only in App Service plan. This is tracked by an issue in our repo here. We're working on it - please follow that issue for status. Thanks.

这篇关于从 C# Azure 函数中访问证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:从 C# Azure 函数中访问证书

基础教程推荐