如何使用 Azure Function V2 管理签名证书 [英] How to manage signed certificates with Azure Function V2

查看:17
本文介绍了如何使用 Azure Function V2 管理签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 Azure Functions App on Consumption Plan.加载特定签名证书所需的 Func 应用程序.

I am working on Azure Functions App on Consumption Plan. The Func App required to load a specific signed certificate.

在本地机器中,我将证书设置为个人证书,一切正常.

In local machine I setup the certificate as personal certificate and everything works fine.

在 azure 上发布后,我收到此错误:

After publishing on azure, I am getting this error:

LocalMachine 中有 0 个主题名称为 cert.name 的证书,MyUse scripts/certificates/来生成这个

There are 0 certificates with the subject name cert.name in LocalMachine, MyUse scripts/certificates/ to generate this

在 SO 甚至 Azure Func 文档中都没有关于如何将证书与 azure 函数一起使用的帮助.

Nothing helpful on SO or even in Azure Func documentation on how to use certificate with azure functions.

有人有这方面的经验吗?

Anyone has experience with that?

推荐答案

我明白了,它很简单.

首先进入你的Function App下的平台特性,你应该会找到如下图所示的SSL.

First go to platform features under your Function App and you should find SSL as shown below.

然后您可以根据需要添加公共、私有或 SSL 证书.在我的情况下,我想添加一个我已经导出并拥有它的私钥的私有证书.

Then you can add a public, private or SSL certificate based on your needs. In my case I want to add a private Certificate which i already exported and have it's private key.

上传您的证书后,转到您的应用设置并添加此键/值:

After uploading your certificate, go to your app settings and add this key/value:

WEBSITE_LOAD_CERTIFICATES:您的证书指纹"

WEBSITE_LOAD_CERTIFICATES: "Your Cert Thumbprint"

您应该能够像这样使用此指纹加载证书:

You should be able to load the certificate using this Thumbprint like this:

using System;
using System.Security.Cryptography.X509Certificates;

    ...
    X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    certStore.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certCollection = certStore.Certificates.Find(
                                X509FindType.FindByThumbprint,
                                // Replace below with your certificate's thumbprint
                                "000000000000000000000000000000000000000",
                                false);
    // Get the first cert with the thumbprint
    if (certCollection.Count > 0)
    {
        X509Certificate2 cert = certCollection[0];
        // Use certificate
        Console.WriteLine(cert.FriendlyName);
    }
    certStore.Close();
    ...

这篇关于如何使用 Azure Function V2 管理签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆