开发者

How can I do that in bouncyCastle (get installed certificates)?

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 install开发者_开发百科ed certificates, using bouncy castle?

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


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.


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();

}


Init the Certificate:

Org.BouncyCastle.X509.X509Certificate certificate = new Certificate...

Then:

System.Security.Cryptography.X509Certificates.X509Store CertificateStore = new System.Security.Cryptography.X509Certificates.X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);
CertificateStore.Open(OpenFlags.ReadWrite);
CertificateStore.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(certificate));
CertificateStore.Close();

Pseudo code, as an example as I am away from my working Machine atm, however, this should work nicely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜