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

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

问题描述

我正在使用消费计划上的Azure Functions应用程序. Func App需要加载特定的签名证书.

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脚本/certificates/来生成

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

对于SO或什至在Azure Func文档中没有关于如何将证书与天蓝色函数一起使用都没有帮助.

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

有人对此有经验吗?

推荐答案

我明白了,很简单.

首先转到功能应用程序下的平台功能,您应该找到如下所示的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天全站免登陆