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); }
private void GenerateKey() { var sb = new StringBuilder(); sb.Append("Error generating Key").Append(Environment.NewLine); if (Model.Password.IsNullOrEmpty()) { sb.Append("Enter Password!").Append(Environment.NewLine); } if (Model.Salt.IsNullOrEmpty()) { sb.Append("Enter Salt!").Append(Environment.NewLine); } if (Model.KeySize <= 0) { sb.Append("Enter KeySize!").Append(Environment.NewLine); } if (!Model.BouncyImplementation && Model.Iterations <= 0) { sb.Append("Enter Iterations value!").Append(Environment.NewLine); } if (Model.BouncyImplementation && Model.Digest == null) { sb.Append("Select Digest!").Append(Environment.NewLine); } if (Model.BouncyImplementation && Model.DerivationFunction == null) { sb.Append("Select derivation function!").Append(Environment.NewLine); } var errors = sb.ToString(); if (!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(errors)); IsMessageBoxVisible = true; return; } byte[] password = Encoding.UTF32.GetBytes(Model.Password); byte[] salt = Encoding.UTF32.GetBytes(Model.Salt); if (Model.BouncyImplementation) { Model.Key = new byte[Model.KeySize]; var digest = Model.Digest.Instance <IDigest>(); var kdf = Model.DerivationFunction.Instance <BaseKdfBytesGenerator>(digest); var kdfParams = new KdfParameters(password, salt); kdf.Init(kdfParams); kdf.GenerateBytes(Model.Key, 0, Model.Key.Length); } else { var k1 = new Rfc2898DeriveBytes(password, salt, Model.Iterations); Model.Key = k1.GetBytes(Model.KeySize); } }
private void CommandExecuted(object o) { var pboxes = (object[])o; var sb = new StringBuilder(); char[] password1 = ((PasswordBox)pboxes[0]).Password.ToArray(); char[] password2 = ((PasswordBox)pboxes[1]).Password.ToArray(); if (password1.Length == 0) { sb.Append("please enter a password").Append(Environment.NewLine); } if (!password1.SequenceEqual(password2)) { sb.Append("password and confirm do not match").Append(Environment.NewLine); } if (Path.IsNullOrEmpty()) { sb.Append("please select a path ").Append(Environment.NewLine); } if (AlgorithmRequired && SelectedAlgorithm.IsNullOrEmpty()) { sb.Append("please select an algorithm ").Append(Environment.NewLine); } Array.Clear(password1, 0, password1.Length); Array.Clear(password2, 0, password2.Length); var errors = sb.ToString(); if (!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error("Error exporting to file - " + Environment.NewLine + errors)); IsMessageBoxVisible = true; return; } char[] password = ((PasswordBox)pboxes[0]).Password.ToArray(); if (AlgorithmRequired) { _action.Invoke(_entry, SelectedAlgorithm, password, Path); } else { _exportPkcs12Action.Invoke(_entry, Path, password); } }
private void Process(bool forEncryption) { String errors = Validate(); if (!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(errors)); IsMessageBoxVisible = true; return; } // TODO: var iv = new byte[Blocksize]; try { using (Stream istream = File.Open(BlockCipherModel.Path, FileMode.Open)) { String outputFilePath = FileUtils.ChangeFilename(BlockCipherModel.Path, forEncryption ? "_encrypted" : "_decrypted"); using (Stream ostream = File.Create(outputFilePath)) { if (BlockCipherModel.BouncyImplementation) { EncryptUsingBC(istream, ostream, iv, forEncryption); } else { EncryptUsingDotNet(istream, ostream, iv, forEncryption); } } } } catch (Exception e) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(e.Message, "Details", e.StackTrace)); IsMessageBoxVisible = true; } }
private void Load(object o) { if (o == null) { _action.Invoke(new KeyStoreViewModel(Model.SystemStoreName, Model.SystemStoreLocation)); } else if (o is PasswordBox) { char[] password = ((PasswordBox)o).Password.ToCharArray(); try { _action.Invoke(new KeyStoreViewModel(password, Model.KeyStorePath)); } catch (Exception ex) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(ex.Message, "Details", ex.StackTrace)); IsMessageBoxVisible = true; } } }
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); }
private void Load(object o) { if (o == null) _action.Invoke(new KeyStoreViewModel(Model.SystemStoreName, Model.SystemStoreLocation)); else if (o is PasswordBox) { char[] password = ((PasswordBox) o).Password.ToCharArray(); try { _action.Invoke(new KeyStoreViewModel(password, Model.KeyStorePath)); } catch (Exception ex) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(ex.Message, "Details", ex.StackTrace)); IsMessageBoxVisible = true; } } }
private void CommandExecuted(object o) { var pboxes = (object[])o; var sb = new StringBuilder(); char[] password1 = ((PasswordBox) pboxes[0]).Password.ToArray(); char[] password2 = ((PasswordBox)pboxes[1]).Password.ToArray(); if (password1.Length == 0) { sb.Append("please enter a password").Append(Environment.NewLine); } if (!password1.SequenceEqual(password2)) { sb.Append("password and confirm do not match").Append(Environment.NewLine); } if (Path.IsNullOrEmpty()) { sb.Append("please select a path ").Append(Environment.NewLine); } if (AlgorithmRequired && SelectedAlgorithm.IsNullOrEmpty()) { sb.Append("please select an algorithm ").Append(Environment.NewLine); } Array.Clear(password1, 0, password1.Length); Array.Clear(password2, 0, password2.Length); var errors = sb.ToString(); if(!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error("Error exporting to file - " + Environment.NewLine + errors)); IsMessageBoxVisible = true; return; } char[] password = ((PasswordBox) pboxes[0]).Password.ToArray(); if (AlgorithmRequired) { _action.Invoke(_entry, SelectedAlgorithm, password, Path); } else { _exportPkcs12Action.Invoke(_entry, Path, password); } }
private void GenerateKey() { var sb = new StringBuilder(); sb.Append("Error generating Key").Append(Environment.NewLine); if(Model.Password.IsNullOrEmpty()) { sb.Append("Enter Password!").Append(Environment.NewLine); } if(Model.Salt.IsNullOrEmpty()) { sb.Append("Enter Salt!").Append(Environment.NewLine); } if (Model.KeySize <= 0) { sb.Append("Enter KeySize!").Append(Environment.NewLine); } if (!Model.BouncyImplementation && Model.Iterations <= 0) { sb.Append("Enter Iterations value!").Append(Environment.NewLine); } if (Model.BouncyImplementation && Model.Digest == null) { sb.Append("Select Digest!").Append(Environment.NewLine); } if (Model.BouncyImplementation && Model.DerivationFunction == null) { sb.Append("Select derivation function!").Append(Environment.NewLine); } var errors = sb.ToString(); if (!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(errors)); IsMessageBoxVisible = true; return; } byte[] password = Encoding.UTF32.GetBytes(Model.Password); byte[] salt = Encoding.UTF32.GetBytes(Model.Salt); if (Model.BouncyImplementation) { Model.Key = new byte[Model.KeySize]; var digest = Model.Digest.Instance<IDigest>(); var kdf = Model.DerivationFunction.Instance<BaseKdfBytesGenerator>(digest); var kdfParams = new KdfParameters(password, salt); kdf.Init(kdfParams); kdf.GenerateBytes(Model.Key, 0, Model.Key.Length); } else { var k1 = new Rfc2898DeriveBytes(password, salt, Model.Iterations); Model.Key = k1.GetBytes(Model.KeySize); } }
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); }
private void Process(bool forEncryption) { String errors = Validate(); if (!errors.IsNullOrEmpty()) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(errors)); IsMessageBoxVisible = true; return; } // TODO: var iv = new byte[Blocksize]; try { using (Stream istream = File.Open(BlockCipherModel.Path, FileMode.Open)) { String outputFilePath = FileUtils.ChangeFilename(BlockCipherModel.Path, forEncryption ? "_encrypted" : "_decrypted"); using (Stream ostream = File.Create(outputFilePath)) { if (BlockCipherModel.BouncyImplementation) { EncryptUsingBC(istream, ostream, iv, forEncryption); } else { EncryptUsingDotNet(istream, ostream, iv, forEncryption); } } } } catch (Exception e) { MessageBoxContent = new MessageBoxViewModel(CloseMessageBox, MessageBoxModel.Error(e.Message,"Details",e.StackTrace)); IsMessageBoxVisible = true; } }