Get Private Key from BouncyCastle X509 Certificate? C#

前端 未结 3 1678
北荒
北荒 2021-02-05 15:51

Normally when I grab an X509Certificate2 out of my keystore I can call .PrivateKey to retrieve the cert\'s private key as an AsymmetricAlgorithm<

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 16:27

    Find .NET X509Certificate2:

    X509Certificate2 cert = this.FindCertificate(certificateFriendlyName);
    

    Parse it to BouncyCastle certificate and use X509Certificate2Signature to get signature:

    var parser = new X509CertificateParser();
    var bouncyCertificate = parser.ReadCertificate(cert.RawData);
    var algorithm = DigestAlgorithms.GetDigest(bouncyCertificate.SigAlgOid);
    var signature = new X509Certificate2Signature(cert, algorithm);
    

提交回复
热议问题