How can I do that in bouncyCastle (get installed c

2019-04-29 09:26发布

问题:

Ok, I am quite new to the crypto world of bouncyCastle, and perhaps is a mental block, I can't seem to find(/google for) the equivalent to:

X509Store store = 
new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);

I think it might be the easiest and dumbest thing, but how can I access the windows installed certificates, using bouncy castle?

Or if I can't, how can i convert my System.Security.Cryptography.X509Certificates.X509Certificate2 to Org.BouncyCastle.X509.X509Certificate?

回答1:

Bouncycastle doesn't have access to Windows certificates store, that is the role of Microsoft's .NET classes. To convert between .NET certificates and their Bouncycastle equivalents look at the methods in the Org.BouncyCastle.Security.DotNetUtilities class, particularly the ToX509Certificate and FromX509Certificate methods.



回答2:

I convert the System.Security.Cryptography.X509Certificates.X509Certificate2 to a Org.BouncyCastle.X509.X509Certificate using the following method

public static org.bouncycastle.x509.X509Certificate 
        convertToBCX509Certificate(X509Certificate2 cert) {

    X509CertificateParser parser = 
            new X509CertificateParser(cert.Export(X509ContentType.Cert));
    return parser.ReadCertificate();

}