1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- using ComPDFKit.DigitalSign;
- using Compdfkit_Tools.Helper;
- using System;
- using System.ComponentModel;
- using System.Runtime.CompilerServices;
- using System.Security;
- using System.Windows;
- using System.Windows.Controls;
- namespace Compdfkit_Tools.PDFControl
- {
- /// <summary>
- /// SaveCerficateControlControl.xaml 的交互逻辑
- /// </summary>
- public partial class SaveCerficateControl : UserControl, INotifyPropertyChanged
- {
- public CertificateInfo CertificateInfo;
- public event PropertyChangedEventHandler PropertyChanged;
- private string _filePath;
- public string FilePath
- {
- get => _filePath;
- set => UpdateProper(ref _filePath, value);
- }
- public SaveCerficateControl()
- {
- InitializeComponent();
- this.DataContext = this;
- }
- private void SelectFileBtn_Click(object sender, RoutedEventArgs e)
- {
- string filePath = CommonHelper.GetGeneratePathOrEmpty("PFX Files(*.pfx) | *.pfx");
- if (filePath != string.Empty)
- {
- FilePath = filePath;
- }
- }
-
- private void DoneBtn_Click(object sender, RoutedEventArgs e)
- {
- if(FilePath == string.Empty)
- {
- return;
- }
- if (SetPasswordPbx.Password != string.Empty && SetPasswordPbx.Password == ConfirmPasswordPbx.Password)
- {
- CertificateInfo.Password = SetPasswordPbx.Password;
- }
- else
- {
- return;
- }
- string certificateInfo = "/";
- certificateInfo += "C=" + CertificateInfo.Area;
- if (CertificateInfo.Organization != string.Empty)
- {
- certificateInfo += "/O=" + CertificateInfo.Organization;
- }
- if (CertificateInfo.OrganizationUnit != string.Empty)
- {
- certificateInfo += "/D=" + CertificateInfo.OrganizationUnit;
- }
- certificateInfo += "/CN=" + CertificateInfo.GrantorName;
- bool is_2048 = CertificateInfo.AlgorithmType == AlgorithmType.RSA2048bit;
- CPDFPKCS12CertHelper.GeneratePKCS12Cert(certificateInfo, CertificateInfo.Password, FilePath, CertificateInfo.PurposeType, is_2048);
- FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog();
- fillDigitalSignatureDialog.FilePath = FilePath;
- fillDigitalSignatureDialog.ShowDialog();
- }
- protected void UpdateProper<T>(ref T properValue,
- T newValue,
- [CallerMemberName] string properName = "")
- {
- if (object.Equals(properValue, newValue))
- return;
- properValue = newValue;
- OnPropertyChanged(properName);
- }
-
- protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
|