Ejemplo n.º 1
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                if (cadlg.ShowDialog() == DialogResult.OK)
                {
                    if (cadlg.FileName.EndsWith(".p12") || cadlg.FileName.EndsWith(".pfx"))
                    {
                        PassForm frm = new PassForm();
                        frm.ShowDialog();
                        if (frm.pass != null)
                        {
                            textBoxX1.Text = cadlg.FileName;

                            using (var bio = BIO.File(cadlg.FileName, "r"))
                                PFX = new PKCS12(bio, frm.pass);
                            CACert            = new System.Security.Cryptography.X509Certificates.X509Certificate2(PFX.Certificate.DER);
                            stepItem5.Value   = 50;
                            textBoxX3.Enabled = true;
                            buttonX3.Enabled  = true;
                            buttonX2.Enabled  = true;
                        }
                        else
                        {
                            throw new ArgumentException("PKCS12 password was not defined");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message, "CA Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 2
0
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                if (cadlg.ShowDialog() == DialogResult.OK)
                {
                    if (cadlg.FileName.EndsWith(".p12") || cadlg.FileName.EndsWith(".pfx"))
                    {
                        PassForm frm = new PassForm();
                        frm.ShowDialog();
                        if (frm.pass != null)
                        {
                            textBoxX1.Text = cadlg.FileName;


                            CACert = new System.Security.Cryptography.X509Certificates.X509Certificate2(cadlg.FileName, frm.pass);
                            Al.Security.Pkcs.Pkcs12Store st = new Al.Security.Pkcs.Pkcs12Store(File.OpenRead(cadlg.FileName), frm.pass.ToCharArray());
                            IEnumerator en = st.Aliases.GetEnumerator();
                            en.MoveNext();
                            CP = st.GetKey(en.Current.ToString()).Key;
                            //        System.Security.Cryptography.RSACryptoServiceProvider rsa = (System.Security.Cryptography.RSACryptoServiceProvider)CACert.PrivateKey;

                            stepItem5.Value       = 100;
                            buttonX2.Enabled      = true;
                            superTabItem1.Visible = true;
                        }
                        else
                        {
                            throw new ArgumentException("PKCS12 password was not defined");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message, "CA Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }