private void Create_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrEmpty(SubjectField.Text)) { throw new FormatException(); } if (string.IsNullOrEmpty(CertificateField.Text)) { throw new FormatException(); } var pass = PasswordField.SecurePassword; var checkPass = CheckPasswordField.SecurePassword; if (!Equals(pass, checkPass)) { throw new FormatException(); } CertificatePath = CertificateField.Text; var subject = "CN=" + string.Format(_subjectFormat, SubjectField.Text); var from = DateTime.UtcNow; var to = DateTime.UtcNow.AddYears(4); var certBlob = CertificateGenerator.CreateSelfSignedPfx(subject, from, to, pass); File.WriteAllBytes(CertificateField.Text, certBlob); DialogResult = true; } catch (FormatException) { MessageBox.Show(this, Localizer.Instance.Localize("fieldsError"), "TCP Chat"); } }