代码之家  ›  专栏  ›  技术社区  ›  Marzouk

如何使用Azure函数v2管理签名证书

  •  1
  • Marzouk  · 技术社区  · 7 年前

    我正在使用Azure功能应用程序制定消费计划。func应用程序需要加载特定的签名证书。

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

    在Azure上发布后,我收到以下错误:

    localmachine中有0个主题名为cert.name的证书,myuse scripts/certificates/生成此证书

    关于如何将证书与Azure函数一起使用,即使在Azure func文档中也没有任何帮助。

    有人对此有经验吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Marzouk    7 年前

    我明白了,而且很直接。

    首先转到你的功能应用下的平台功能,你应该找到如下所示的SSL。

    enter image description here

    然后,您可以根据需要添加公共、私有或SSL证书。在我的例子中,我想添加一个已经导出的私有证书,它是私有密钥。

    enter image description here

    上载证书后,转到应用程序设置并添加此密钥/值:

    网站加载证书:“您的证书指纹”

    您应该能够使用如下的指纹加载证书:

    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();
        ...