private void processCert() { string alias = null; PKCS12Store pk12; //First we'll read the certificate file pk12 = new PKCS12Store(new FileStream(this.Path, FileMode.Open, FileAccess.Read), this.password.ToCharArray()); //then Iterate throught certificate entries to find the private key entry IEnumerator i = pk12.aliases(); while (i.MoveNext()) { alias = ((string)i.Current); if (pk12.isKeyEntry(alias)) { break; } } this.akp = pk12.getKey(alias).getKey(); X509CertificateEntry[] ce = pk12.getCertificateChain(alias); this.chain = new org.bouncycastle.x509.X509Certificate[ce.Length]; for (int k = 0; k < ce.Length; ++k) { chain[k] = ce[k].getCertificate(); } }
private void CreateKeystore( String myAlias, String peerAlias, AsymmetricCipherKeyPair myKey, X509Certificate myCert, X509Certificate peerCert, String filename, String password) { PKCS12Store pkcs12 = new PKCS12Store(); pkcs12.setKeyEntry( myAlias, new AsymmetricKeyEntry(myKey.getPrivate()), new X509CertificateEntry[] { new X509CertificateEntry(myCert) }); pkcs12.setCertificateEntry(peerAlias, new X509CertificateEntry(peerCert)); System.IO.FileStream stream = new System.IO.FileStream( keystoreFolder + "\\" + filename + ".p12", System.IO.FileMode.Create); pkcs12.save(stream, password.ToCharArray(), new SecureRandom()); stream.Close(); }
private void processCert() { try{ string alias = null; PKCS12Store pk12; pk12 = new PKCS12Store(new FileStream(this.Path, FileMode.Open, FileAccess.Read), this.password.ToCharArray()); //First we'll read the certificate file //then Iterate throught certificate entries to find the private key entry IEnumerator i = pk12.aliases(); while (i.MoveNext()) { alias = ((string)i.Current); if (pk12.isKeyEntry(alias)) break; } this.akp = pk12.getKey(alias).getKey(); X509CertificateEntry[] ce = pk12.getCertificateChain(alias); this.chain = new org.bouncycastle.x509.X509Certificate[ce.Length]; for (int k = 0; k < ce.Length; ++k) chain[k] = ce[k].getCertificate(); } catch (Exception e) { } }
public FolaighKeyStore(char[] password) { init(password); store = new PKCS12Store(); }
private void load(char[] password, Stream fstream) { store = new PKCS12Store(fstream, password); fstream.Close(); }