void NewCertificate(object o) { var errors = ValidateInputs(); if (!errors.ToString().IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error("Errors generating Certificate - " + Environment.NewLine + errors.ToString())); IsMessageBoxVisible = true; return; } var keygen = KeyPairUtils.CreateGenerator(Repository.Srand, Model.KeyPairGenerator, Model.KeyStrength); var keypair = keygen.GenerateKeyPair(); //load the ca pfx file var caStore = X509Utils.LoadCAPfx(Repository.Instance.KeyStorePassword); var caCert = caStore.GetCertificate("ca").Certificate; var caKey = caStore.GetKey("ca").Key; var cert = X509Utils.GenerateUserCertificate(Model.X509Name, caCert.SubjectDN, Model.Validity, keypair.Public, caKey, Model.SignatureAlgorithm, KeyUsageUtils.GetKeyUsage(Model.KeyUsages), Model.ExtendedKeyUsages == null ? null : new ExtendedKeyUsage( KeyUsageUtils.GetExtendedKeyUsages( Model.ExtendedKeyUsages))); _newCertCompletedAction.Invoke(Model.CommonName, cert, keypair); }
void NewKeyStore(object o) { var passwordBoxes = (object[])o; var errors = ValidateInputs(passwordBoxes); if (!errors.ToString().IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error("Errors generating Certificate - " + Environment.NewLine + errors.ToString())); IsMessageBoxVisible = true; return; } var password = ((PasswordBox)passwordBoxes[0]).Password.ToCharArray(); var keygen = KeyPairUtils.CreateGenerator(Repository.Srand, Model.KeyPairGenerator, Model.KeyStrength); var keypair = keygen.GenerateKeyPair(); var repo = Repository.Instance; repo.NewCertificateAuthority(Model.CARepositoryPath, password); repo.KeyPairType = Model.KeyPairType; var cert = X509Utils.GenerateCACertificate(Model.X509Name, Model.Validity, keypair.Public, keypair.Private, Model.SignatureAlgorithm, KeyUsageUtils.GetKeyUsage(Model.KeyUsages), Model.ExtendedKeyUsages == null ? null : new ExtendedKeyUsage(KeyUsageUtils.GetExtendedKeyUsages(Model.ExtendedKeyUsages)), Model.PathLenContraint); X509Utils.ExportPKCS12(Repository.Instance.CAKeyStore, /*Model.CommonName*/ "ca", keypair.Private, password, cert); File.WriteAllText(Repository.CaPfxFilename, PemUtilities.Encode(cert)); _newCaCompletedAction.Invoke(new KeyStoreViewModel(password, Model.CARepositoryPath)); //KeyStoreViewModelEx.Instance.Load(password); }