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 { /// /// SaveCerficateControlControl.xaml 的交互逻辑 /// public partial class SaveCerficateControl : UserControl, INotifyPropertyChanged { public CertificateInfo CertificateInfo; public event PropertyChangedEventHandler PropertyChanged; public event EventHandler FillSignatureEvent; 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; if(CPDFPKCS12CertHelper.GeneratePKCS12Cert(certificateInfo, CertificateInfo.Password, FilePath, CertificateInfo.PurposeType, is_2048)) { FillDigitalSignatureDialog fillDigitalSignatureDialog = new FillDigitalSignatureDialog(); CertificateAccess certificateAccess = new CertificateAccess() { filePath = FilePath, password = CertificateInfo.Password }; FillSignatureEvent?.Invoke(sender, certificateAccess); } } protected void UpdateProper(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)); } }