【问题标题】:Unable to use Let's encrypt certificate into Azure Web App无法使用让我们将证书加密到 Azure Web App
【发布时间】:2019-09-26 07:33:03
【问题描述】:

我刚刚将此插件安装到我的 azure webapp 中 https://github.com/shibayan/azure-appservice-letsencrypt

它可以完美地用作我的自定义域上托管的 SSL 证书。

但是现在,我需要使用这个证书在我的后端进行签名操作(它是一个身份服务器)

所以这是我使用位于startup.cs 中的证书的代码:

using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
    store.Open(OpenFlags.ReadOnly);
    var col = store.Certificates.Find(X509FindType.FindByThumbprint, "mythumbprint", false);
    if (col.Count > 0)
    {
      builder.AddSigningCredential(col[0]); // the builder of identityserver
    }
    else
    {
        throw new Exception("Startup Error: Unable to find signing certificate");
    }

    _logger.LogInformation(col[0].PublicKey.Key.KeyExchangeAlgorithm);    
}

除了我尝试访问公钥的那一行之外,启动工作正常:

col[0].PublicKey.Key.KeyExchangeAlgorithm

我收到此异常:

System.NotSupportedException:证书密钥算法不是 支持的。在 System.Security.Cryptography.X509Certificates.PublicKey.get_Key()

根据 dotnet 核心文档 (https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.publickey.key?view=netframework-4.8) 和 github (https://github.com/dotnet/corefx/blob/master/src/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/PublicKey.cs),仅支持 RSA 和 DSA。

所以我的问题是:我能做什么?我尝试将证书转换为 pfx 文件,但我没有找到此证书的私钥(我只有指纹)

【问题讨论】:

    标签: c# asp.net-core identityserver4 lets-encrypt x509certificate2


    【解决方案1】:

    您不需要使用 CA 颁发的证书进行令牌签名,因此您可以自行颁发。在 Windows 上,以下命令将生成具有正确属性的证书:

    makecert -r -pe -n "CN=MyCertName" -b 01/01/2019 -e 01/01/2039 -eku 1.3.6.1.5.5.7.3.3 -sky signature -a sha256 -len 2048 -ss my -sr LocalMachine
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 2020-07-20
      • 2020-08-26
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2016-12-28
      • 2019-03-25
      相关资源
      最近更新 更多