public static mx509.X509Certificate OpenSslX509ToMonoX509(ox509.X509Certificate cert) { BIO bio = BIO.MemoryBuffer(true); cert.Write(bio); byte[] raw = new byte[bio.BytesPending]; bio.Read(raw, raw.Length); bio.Dispose(); return(new mx509.X509Certificate(raw)); }
private void buttonX1_Click(object sender, EventArgs e) { try { superValidator1.SetValidator1(textBoxX1, null); superValidator1.SetValidator1(c, null); if (pem.Checked) { // superValidator1.SetValidator1(textBoxX1, new DevComponents.DotNetBar.Validator.RequiredFieldValidator("Password is required for Key Encryption")); superValidator1.SetValidator1(c, new DevComponents.DotNetBar.Validator.RequiredFieldValidator("Cipher is required for Key Encryption")); } //else if(pfx.Checked) // superValidator1.SetValidator1(textBoxX1, new DevComponents.DotNetBar.Validator.RequiredFieldValidator("Password is required for Key Encryption")); if (superValidator1.Validate()) { superValidator1.SetValidator1(textBoxX1, null); superValidator1.SetValidator1(c, null); string devpath = ""; if (MainForm.cai != null) { if (MainForm.cai.DevPath != null) { devpath = MainForm.cai.DevPath; } } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Origisign Temp Certificate|*.ogtc"; if (devpath != "") { sfd.InitialDirectory = devpath; } if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileName = sfd.FileName; //if (pkcs7.Checked) // File.WriteAllBytes(Path.ChangeExtension(FileName, ".p7b"), certificate.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Pkcs7)); if (pfx.Checked) { using (var bio = BIO.File(Path.ChangeExtension(FileName, ".pfx"), "w")) { OpenSSL.Core.Stack <X509Certificate> caStack = new OpenSSL.Core.Stack <X509Certificate>(); // caStack.Add(certificate); using (var pfx12 = new PKCS12(textBoxX1.Text, Key, certificate, caStack)) pfx12.Write(bio); } } if (cert.Checked) { using (var bio = BIO.File(Path.ChangeExtension(FileName, ".cer"), "w")) certificate.Write(bio); } if (pem.Checked) { ComboItem ci = (ComboItem)c.SelectedItem; using (var bio = BIO.File(Path.ChangeExtension(FileName, ".key"), "w")) Key.WritePrivateKey(bio, (Cipher)ci.Value, textBoxX1.Text); } this.Close(); } } } catch (Exception ex) { MessageBoxEx.Show(ex.Message, "Export Failed", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }