CertificateDetailControl.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using ComPDFKit.DigitalSign;
  18. namespace Compdfkit_Tools.PDFControl
  19. {
  20. public partial class CertificateDetailControl : UserControl,INotifyPropertyChanged
  21. {
  22. private string version;
  23. public string Version
  24. {
  25. get => version;
  26. set => UpdateProper(ref version, value);
  27. }
  28. private string algorithm;
  29. public string Algorithm
  30. {
  31. get => algorithm;
  32. set => UpdateProper(ref algorithm, value);
  33. }
  34. private string subject;
  35. public string Subject
  36. {
  37. get => subject;
  38. set => UpdateProper(ref subject, value);
  39. }
  40. private string issuer;
  41. public string Issuer
  42. {
  43. get => issuer;
  44. set => UpdateProper(ref issuer, value);
  45. }
  46. private string serialNumber;
  47. public string SerialNumber
  48. {
  49. get => serialNumber;
  50. set => UpdateProper(ref serialNumber, value);
  51. }
  52. private string validityFrom;
  53. public string ValidityFrom
  54. {
  55. get => validityFrom;
  56. set => UpdateProper(ref validityFrom, value);
  57. }
  58. private string validityTo;
  59. public string ValidityTo
  60. {
  61. get => validityTo;
  62. set => UpdateProper(ref validityTo, value);
  63. }
  64. private string certificatePolicy;
  65. public string CertificatePolicy
  66. {
  67. get => certificatePolicy;
  68. set => UpdateProper(ref certificatePolicy, value);
  69. }
  70. private string crlDistributionPoint;
  71. public string CrlDistributionPoint
  72. {
  73. get => crlDistributionPoint;
  74. set => UpdateProper(ref crlDistributionPoint, value);
  75. }
  76. private string authorityInfoAccess;
  77. public string AuthorityInfoAccess
  78. {
  79. get => authorityInfoAccess;
  80. set => UpdateProper(ref authorityInfoAccess, value);
  81. }
  82. private string authorityKeyIdentifier;
  83. public string AuthorityKeyIdentifier
  84. {
  85. get => authorityKeyIdentifier;
  86. set => UpdateProper(ref authorityKeyIdentifier, value);
  87. }
  88. private string subjectKeyIdentifier;
  89. public string SubjectKeyIdentifier
  90. {
  91. get => subjectKeyIdentifier;
  92. set => UpdateProper(ref subjectKeyIdentifier, value);
  93. }
  94. private string basicConstraints;
  95. public string BasicConstraints
  96. {
  97. get => basicConstraints;
  98. set => UpdateProper(ref basicConstraints, value);
  99. }
  100. private string keyUsage;
  101. public string KeyUsage
  102. {
  103. get => keyUsage;
  104. set => UpdateProper(ref keyUsage, value);
  105. }
  106. private string publicKey;
  107. public string PublicKey
  108. {
  109. get => publicKey;
  110. set => UpdateProper(ref publicKey, value);
  111. }
  112. private string x509Data;
  113. public string X509Data
  114. {
  115. get => x509Data;
  116. set => UpdateProper(ref x509Data, value);
  117. }
  118. private string sha1Abstract;
  119. public string SHA1Digest
  120. {
  121. get => sha1Abstract;
  122. set => UpdateProper(ref sha1Abstract, value);
  123. }
  124. private string md5Digest;
  125. public string MD5Digest
  126. {
  127. get => md5Digest;
  128. set => UpdateProper(ref md5Digest, value);
  129. }
  130. public CertificateDetailControl()
  131. {
  132. InitializeComponent();
  133. DataContext = this;
  134. }
  135. public void LoadDetailInfo(CPDFSignatureCertificate certificate)
  136. {
  137. string certificatePolicyText = string.Empty;
  138. string crlDistributionPointText = string.Empty;
  139. string authorityInfoAccessText = string.Empty;
  140. string keyUsageText = string.Empty;
  141. var usageList = DictionaryValueConverter.GetUsage(certificate);
  142. foreach (var policy in certificate.CertificatePolicies)
  143. {
  144. certificatePolicyText += policy + "\n";
  145. }
  146. foreach (var access in certificate.AuthorityInfoAccess)
  147. {
  148. authorityInfoAccess += access + "\n";
  149. }
  150. foreach (var crl in certificate.CRLDistributionPoints)
  151. {
  152. crlDistributionPointText += crl + "\n";
  153. }
  154. for(int i = 0; i < usageList.Count; i++)
  155. {
  156. keyUsageText += usageList[i];
  157. keyUsageText += (i == usageList.Count - 1) ? "" : ", ";
  158. }
  159. Version = certificate.Version.ToString();
  160. Algorithm = certificate.SignatureAlgorithmType.ToString().Substring(26) + "(" + certificate.SignatureAlgorithmOID + ")";
  161. Subject = certificate.Subject;
  162. Issuer = certificate.Issuer;
  163. SerialNumber = certificate.SerialNumber;
  164. validityFrom = certificate.ValidityStarts;
  165. ValidityTo = certificate.ValidityEnds;
  166. CertificatePolicy = certificatePolicyText;
  167. CrlDistributionPoint = crlDistributionPointText;
  168. X509Data = certificate.X509Data;
  169. AuthorityInfoAccess = authorityInfoAccess;
  170. AuthorityKeyIdentifier = certificate.AuthorityKeyIdentifier;
  171. SubjectKeyIdentifier = certificate.SubjectKeyIdentifier;
  172. BasicConstraints = certificate.BasicConstraints;
  173. KeyUsage = keyUsageText;
  174. PublicKey = certificate.PublicKey;
  175. SHA1Digest = certificate.SHA1Digest;
  176. MD5Digest = certificate.MD5Digest;
  177. }
  178. public event PropertyChangedEventHandler PropertyChanged;
  179. protected void UpdateProper<T>(ref T properValue,
  180. T newValue,
  181. [CallerMemberName] string properName = "")
  182. {
  183. if (object.Equals(properValue, newValue))
  184. return;
  185. properValue = newValue;
  186. OnPropertyChanged(properName);
  187. }
  188. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  189. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  190. }
  191. }