Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static X509Certificate CreateDotNetCertificate(Org.BouncyCastle.X509.X509Certificate certificate, AsymmetricCipherKeyPair keyPair)
- {
- var store = new Pkcs12Store();
- string friendlyName = certificate.SubjectDN.ToString();
- var certificateEntry = new X509CertificateEntry(certificate);
- store.SetCertificateEntry(friendlyName, certificateEntry);
- store.SetKeyEntry(friendlyName, new AsymmetricKeyEntry(keyPair.Private), new[] { certificateEntry });
- var stream = new MemoryStream();
- var password = "a password";
- store.Save(stream, password.ToCharArray(), new SecureRandom(randomGenerator));
- return new X509Certificate2(stream.ToArray(), password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement