Saml请求使用数据库中存储的证书进行签名



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

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

    CertificateUtil.Load
    

    此方法有5个重载,但它要求存储证书的路径。我能用的方法吗

    CertificateUtil.LoadBytes
    

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

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

您可以将证书保存在数据库中作为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));

最新更新