1

我在我的应用程序中使用多个身份提供程序。SAML 登录和断言运行良好。我的问题是关于使用证书签署 SAML 消息。

  1. 我将每个 Idp 的证书存储在数据库中,并希望在运行时加载它。在演示应用程序中,证书保存在物理路径上并使用以下方式加载,

    CertificateUtil.Load
    

    此方法有 5 个重载,但它要求提供存储证书的路径。可以用这个方法吗

    CertificateUtil.LoadBytes
    

    从字符串加载证书?因为我看不到任何例子?

  2. 证书需要安装在系统上吗?

4

1 回答 1

1

您可以将数据库中的证书保存为 base64 编码字符串。

要从证书文件(包括私钥)创建 base64 编码字符串:

var certificate = ITfoxtec.Identity.Saml2.Util.CertificateUtil.Load("... certificate file path ...", "... password ...", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
var base64EncodeCertificate = Convert.ToBase64String(certificate.Export(X509ContentType.Pfx));

要从 base64 编码字符串获取证书:

var certificate = new X509Certificate2(Convert.FromBase64String(base64EncodeCertificate));
于 2021-04-26T08:00:19.603 回答