public bool Convert()
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter           = @"Der files (*.der)|*.der|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string file = dlg.FileName;

                    X509Certificate certificate = IOPEMUtils.LoadPemCertificate(View.CertificateFile);

                    IODERUtils.SaveEncodedCertificate(certificate, file);

                    MessageBox.Show(String.Format("Ficheiro gravado em '{0}'", file), @"Informação",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information
                                    );

                    return(true);
                }

                return(false);
            }
        }
예제 #2
0
        public bool Generate()
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter =
                    @"X.509 Certificate files (*.cer;*.crt;*.cert;*.pem)|*.cer;*.crt;*.cert;*.pem|Pem files (*.pem)|*.pem|Crt files (*.crt)|*.crt|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var certificateGenerator = new DefaultServerCertificateGenerator(new DefaultUrlEvaluator());

                    DateTime beginDate = View.From;
                    DateTime endDate   = beginDate.AddDays(View.Duration);


                    X509Certificate         caFile         = IOPEMUtils.LoadPemCertificate(View.CAFile);
                    AsymmetricCipherKeyPair caPriveKeyFile = IOPEMUtils.LoadPemPrivateKey(View.CAPrivateKeyFile);


                    CertificateResult result = certificateGenerator.Create(
                        View.Algoritm,
                        View.KeyLength,
                        View.Subject,
                        View.AlternateNames,
                        beginDate,
                        endDate,
                        View.KeyUsage,
                        View.Purpose,
                        caFile,
                        caPriveKeyFile,
                        new CertificateEndPoints
                    {
                        CaDistributionEndPoint  = View.CaUri,
                        CrlDistributionEndPoint = View.CrlUri,
                        OcspEndPoint            = View.OcspUri
                    }
                        );

                    ResultFileNames files = IOPEMUtils.SaveCertificateAndPrivateKey(result.Certificate, result.KeyPair,
                                                                                    dlg.FileName);

                    MessageBox.Show(
                        String.Format("Foram gravados os ficheiros:\nCertificado como '{0}'\nChave privada como '{1}'",
                                      files.Certificate,
                                      files.PrivateKey), @"Informação",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );

                    return(true);
                }

                return(false);
            }
        }
        public bool Convert()
        {
            string password        = View.Pkcs12Password;
            string confirmPassword = View.Pkcs12PasswordConfirmation;

            if (String.CompareOrdinal(password, confirmPassword) != 0)
            {
                MessageBox.Show(@"A password e confirmação não coincidem", @"Passwords",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );

                return(false);
            }

            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter           = @"Pfx files (*.pfx)|*.pfx|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string file = dlg.FileName;

                    var storeGenerator = new DefaultPkcs12StoreGenerator();

                    X509Certificate         certificateFile         = IOPEMUtils.LoadPemCertificate(View.CertificateFile);
                    AsymmetricCipherKeyPair certificatePriveKeyFile =
                        IOPEMUtils.LoadPemPrivateKey(View.CertificatePrivateKeyFile);

                    try
                    {
                        byte[] result = storeGenerator.Create(certificateFile, certificatePriveKeyFile, password,
                                                              View.CasFiles);

                        File.WriteAllBytes(file, result);

                        MessageBox.Show(String.Format("Lista gravada em '{0}'", file), @"Informação",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information
                                        );
                        return(true);
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show(exp.Message, @"Erro",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                        );
                    }
                }

                return(false);
            }
        }
        public bool Generate()
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter           = @"X.509 Crl files (*.crl)|*.crl|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string file = dlg.FileName;

                    var listGenerator = new DefaultCertificateRevocationListGenerator();

                    DateTime beginDate      = View.From;
                    DateTime nextUpdateDate = beginDate.AddDays(View.NextUpdate);

                    X509Crl                 crlFile        = IOPEMUtils.LoadPemCrl(View.CrlListFile);
                    X509Certificate         caFile         = IOPEMUtils.LoadPemCertificate(View.CAFile);
                    AsymmetricCipherKeyPair caPriveKeyFile = IOPEMUtils.LoadPemPrivateKey(View.CAPrivateKeyFile);

                    string[] certificatesFiles = View.CertificatesFilesToRevocate;
                    List <X509Certificate> certificatesToRevocate = null;
                    if (!certificatesFiles.IsStringListNullOrEmpty())
                    {
                        certificatesToRevocate = certificatesFiles.Select(IOPEMUtils.LoadPemCertificate).ToList();
                    }

                    X509Crl result = listGenerator.Update(
                        View.Algoritm,
                        crlFile,
                        certificatesToRevocate.IsNullOrEmpty() ? null : certificatesToRevocate.ToArray(),
                        caFile,
                        caPriveKeyFile,
                        beginDate,
                        nextUpdateDate,
                        View.Reason
                        );

                    IOPEMUtils.SavePemCrl(result, file);

                    MessageBox.Show(String.Format("Lista gravada em '{0}'", file), @"Informação",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information
                                    );

                    return(true);
                }

                return(false);
            }
        }
        public bool Generate()
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter =
                    @"X.509 Certificate files (*.cer;*.crt;*.cert;*.pem)|*.cer;*.crt;*.cert;*.pem|Pem files (*.pem)|*.pem|Crt files (*.crt)|*.crt|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var certificateGenerator = new DefaultSelfSignedCertificateGenerator();

                    DateTime          beginDate = View.From;
                    DateTime          endDate   = beginDate.AddDays(View.Duration);
                    CertificateResult result    = certificateGenerator.Create(
                        View.Algoritm,
                        View.KeyLength,
                        View.Subject,
                        beginDate,
                        endDate,
                        View.KeyUsage,
                        View.Purpose
                        );

                    ResultFileNames files = IOPEMUtils.SaveCertificateAndPrivateKey(result.Certificate, result.KeyPair,
                                                                                    dlg.FileName);

                    MessageBox.Show(
                        String.Format("Foram gravados os ficheiros:\nCertificado como '{0}'\nChave privada como '{1}'",
                                      files.Certificate,
                                      files.PrivateKey), @"Informação",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information
                        );

                    return(true);
                }
            }

            return(false);
        }
        public bool Generate()
        {
            using (var dlg = new SaveFileDialog())
            {
                dlg.Filter           = @"Crl files (*.crl)|*.crl|All files (*.*)|*.*";
                dlg.FilterIndex      = 0;
                dlg.RestoreDirectory = true;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    string file = dlg.FileName;

                    var listGenerator = new DefaultCertificateRevocationListGenerator();

                    DateTime beginDate      = View.From;
                    DateTime nextUpdateDate = beginDate.AddDays(View.NextUpdate);

                    X509Certificate         caFile         = IOPEMUtils.LoadPemCertificate(View.CAFile);
                    AsymmetricCipherKeyPair caPriveKeyFile = IOPEMUtils.LoadPemPrivateKey(View.CAPrivateKeyFile);

                    X509Crl result = listGenerator.Create(
                        View.Algoritm,
                        caFile,
                        caPriveKeyFile,
                        beginDate,
                        nextUpdateDate
                        );

                    IOPEMUtils.SavePemCrl(result, file);

                    MessageBox.Show(String.Format("Lista gravada em '{0}'", file), @"Informação",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information
                                    );

                    return(true);
                }

                return(false);
            }
        }