void ImportPkcs12(byte[] data, SafePasswordHandle password) { using (var pkcs12 = new MonoBtlsPkcs12()) { if (password == null || password.IsInvalid) { try { // Support both unencrypted PKCS#12.. pkcs12.Import(data, null); } catch { // ..and PKCS#12 encrypted with an empty password using (var empty = new SafePasswordHandle(string.Empty)) pkcs12.Import(data, empty); } } else { pkcs12.Import(data, password); } x509 = pkcs12.GetCertificate(0); if (pkcs12.HasPrivateKey) { nativePrivateKey = pkcs12.GetPrivateKey(); } if (pkcs12.Count > 1) { intermediateCerts = new X509CertificateImplCollection(); for (int i = 0; i < pkcs12.Count; i++) { using (var ic = pkcs12.GetCertificate(i)) { if (MonoBtlsX509.Compare(ic, x509) == 0) { continue; } var impl = new X509CertificateImplBtls(ic); intermediateCerts.Add(impl, true); } } } } }
void ImportPkcs12 (byte[] data, string password) { using (var pkcs12 = new MonoBtlsPkcs12 ()) { if (string.IsNullOrEmpty (password)) { try { // Support both unencrypted PKCS#12.. pkcs12.Import (data, null); } catch { // ..and PKCS#12 encrypted with an empty password pkcs12.Import (data, string.Empty); } } else { pkcs12.Import (data, password); } x509 = pkcs12.GetCertificate (0); if (pkcs12.HasPrivateKey) nativePrivateKey = pkcs12.GetPrivateKey (); if (pkcs12.Count > 1) { intermediateCerts = new X509CertificateImplCollection (); for (int i = 0; i < pkcs12.Count; i++) { using (var ic = pkcs12.GetCertificate (i)) { if (MonoBtlsX509.Compare (ic, x509) == 0) continue; var impl = new X509CertificateImplBtls (ic, true); intermediateCerts.Add (impl, true); } } } } }