简体   繁体   中英

Converting X509Certificate2 certificate into BouncyCastle X509Certificate

I have an object of System.Security.Cryptography.X509Certificates.X509Certificate2. I need to convert it into an object of Org.BouncyCastle.X509.X509Certificate.

Can anyone help me please?

使用Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate ,它获取System.Security.Cryptography.X509Certificates.X509Certificate并返回Org.BouncyCastle.X509.X509Certificate

It's been a while since I played with Bouncy Castle. Basically take X509Certificate2.RawData and pass it to the BC X509Certificate constructor.

If I remember correctly, BC has a Org.BouncyCastle.Security.DotNetUtilities . This should allow you to import a certificate.

Here is how I do that (BouncyCastle.Crypto version 1.8.1.0):

var cert = new Org.BouncyCastle.X509.X509CertificateParser()
    .ReadCertificate(x509Certificate2.GetRawCertData());

In other answers mentioned Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(X509Certificate) works too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM