mscorlib(4.0.0.0) API with additions
X509Certificate2.cs
1 using System.IO;
5 using System.Text;
6 
8 {
10  [Serializable]
12  {
13  private int m_version;
14 
15  private DateTime m_notBefore;
16 
17  private DateTime m_notAfter;
18 
19  private AsymmetricAlgorithm m_privateKey;
20 
21  private PublicKey m_publicKey;
22 
23  private X509ExtensionCollection m_extensions;
24 
25  private Oid m_signatureAlgorithm;
26 
27  private X500DistinguishedName m_subjectName;
28 
29  private X500DistinguishedName m_issuerName;
30 
32 
33  private static int s_publicKeyOffset;
34 
39  public bool Archived
40  {
41  get
42  {
43  if (m_safeCertContext.IsInvalid)
44  {
45  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
46  }
47  uint pcbData = 0u;
48  return CAPISafe.CertGetCertificateContextProperty(m_safeCertContext, 19u, SafeLocalAllocHandle.InvalidHandle, ref pcbData);
49  }
50  set
51  {
52  SafeLocalAllocHandle safeLocalAllocHandle = SafeLocalAllocHandle.InvalidHandle;
53  if (value)
54  {
55  safeLocalAllocHandle = CAPI.LocalAlloc(64u, new IntPtr(Marshal.SizeOf(typeof(CAPIBase.CRYPTOAPI_BLOB))));
56  }
57  if (!CAPI.CertSetCertificateContextProperty(m_safeCertContext, 19u, 0u, safeLocalAllocHandle))
58  {
60  }
61  safeLocalAllocHandle.Dispose();
62  }
63  }
64 
69  {
70  get
71  {
72  if (m_safeCertContext.IsInvalid)
73  {
74  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
75  }
76  if (m_extensions == null)
77  {
78  m_extensions = new X509ExtensionCollection(m_safeCertContext);
79  }
80  return m_extensions;
81  }
82  }
83 
87  public string FriendlyName
88  {
89  get
90  {
91  if (m_safeCertContext.IsInvalid)
92  {
93  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
94  }
95  SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;
96  uint pcbData = 0u;
97  if (!CAPISafe.CertGetCertificateContextProperty(m_safeCertContext, 11u, invalidHandle, ref pcbData))
98  {
99  return string.Empty;
100  }
101  invalidHandle = CAPI.LocalAlloc(0u, new IntPtr(pcbData));
102  if (!CAPISafe.CertGetCertificateContextProperty(m_safeCertContext, 11u, invalidHandle, ref pcbData))
103  {
104  return string.Empty;
105  }
106  string result = Marshal.PtrToStringUni(invalidHandle.DangerousGetHandle());
107  invalidHandle.Dispose();
108  return result;
109  }
110  set
111  {
112  if (m_safeCertContext.IsInvalid)
113  {
114  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
115  }
116  if (value == null)
117  {
118  value = string.Empty;
119  }
120  SetFriendlyNameExtendedProperty(m_safeCertContext, value);
121  }
122  }
123 
127  public unsafe X500DistinguishedName IssuerName
128  {
129  get
130  {
131  if (m_safeCertContext.IsInvalid)
132  {
133  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
134  }
135  if (m_issuerName == null)
136  {
137  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)m_safeCertContext.DangerousGetHandle();
138  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
139  m_issuerName = new X500DistinguishedName(cERT_INFO.Issuer);
140  }
141  return m_issuerName;
142  }
143  }
144 
148  public unsafe DateTime NotAfter
149  {
150  get
151  {
152  if (m_safeCertContext.IsInvalid)
153  {
154  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
155  }
156  if (m_notAfter == DateTime.MinValue)
157  {
158  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)m_safeCertContext.DangerousGetHandle();
159  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
160  long fileTime = (long)(((ulong)(uint)cERT_INFO.NotAfter.dwHighDateTime << 32) | (uint)cERT_INFO.NotAfter.dwLowDateTime);
161  m_notAfter = DateTime.FromFileTime(fileTime);
162  }
163  return m_notAfter;
164  }
165  }
166 
170  public unsafe DateTime NotBefore
171  {
172  get
173  {
174  if (m_safeCertContext.IsInvalid)
175  {
176  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
177  }
178  if (m_notBefore == DateTime.MinValue)
179  {
180  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)m_safeCertContext.DangerousGetHandle();
181  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
182  long fileTime = (long)(((ulong)(uint)cERT_INFO.NotBefore.dwHighDateTime << 32) | (uint)cERT_INFO.NotBefore.dwLowDateTime);
183  m_notBefore = DateTime.FromFileTime(fileTime);
184  }
185  return m_notBefore;
186  }
187  }
188 
193  public bool HasPrivateKey
194  {
195  get
196  {
197  if (m_safeCertContext.IsInvalid)
198  {
199  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
200  }
201  uint pcbData = 0u;
202  return CAPISafe.CertGetCertificateContextProperty(m_safeCertContext, 2u, SafeLocalAllocHandle.InvalidHandle, ref pcbData);
203  }
204  }
205 
214  {
215  get
216  {
217  if (!HasPrivateKey)
218  {
219  return null;
220  }
221  if (m_privateKey == null)
222  {
223  CspParameters parameters = new CspParameters();
224  if (!GetPrivateKeyInfo(m_safeCertContext, ref parameters))
225  {
226  return null;
227  }
228  parameters.Flags |= CspProviderFlags.UseExistingKey;
229  switch (PublicKey.AlgorithmId)
230  {
231  case 9216u:
232  case 41984u:
233  m_privateKey = new RSACryptoServiceProvider(parameters);
234  break;
235  case 8704u:
236  m_privateKey = new DSACryptoServiceProvider(parameters);
237  break;
238  default:
239  throw new NotSupportedException(SR.GetString("NotSupported_KeyAlgorithm"));
240  }
241  }
242  return m_privateKey;
243  }
244  set
245  {
246  if (m_safeCertContext.IsInvalid)
247  {
248  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
249  }
250  ICspAsymmetricAlgorithm cspAsymmetricAlgorithm = value as ICspAsymmetricAlgorithm;
251  if (value != null && cspAsymmetricAlgorithm == null)
252  {
253  throw new NotSupportedException(SR.GetString("NotSupported_InvalidKeyImpl"));
254  }
255  if (cspAsymmetricAlgorithm != null)
256  {
257  if (cspAsymmetricAlgorithm.CspKeyContainerInfo == null)
258  {
259  throw new ArgumentException("CspKeyContainerInfo");
260  }
261  if (s_publicKeyOffset == 0)
262  {
263  s_publicKeyOffset = Marshal.SizeOf(typeof(CAPIBase.BLOBHEADER));
264  }
265  ICspAsymmetricAlgorithm cspAsymmetricAlgorithm2 = PublicKey.Key as ICspAsymmetricAlgorithm;
266  byte[] array = cspAsymmetricAlgorithm2.ExportCspBlob(includePrivateParameters: false);
267  byte[] array2 = cspAsymmetricAlgorithm.ExportCspBlob(includePrivateParameters: false);
268  if (array == null || array2 == null || array.Length != array2.Length || array.Length <= s_publicKeyOffset)
269  {
270  throw new CryptographicUnexpectedOperationException(SR.GetString("Cryptography_X509_KeyMismatch"));
271  }
272  for (int i = s_publicKeyOffset; i < array.Length; i++)
273  {
274  if (array[i] != array2[i])
275  {
276  throw new CryptographicUnexpectedOperationException(SR.GetString("Cryptography_X509_KeyMismatch"));
277  }
278  }
279  }
280  SetPrivateKeyProperty(m_safeCertContext, cspAsymmetricAlgorithm);
281  m_privateKey = value;
282  }
283  }
284 
288  public PublicKey PublicKey
289  {
290  get
291  {
292  if (m_safeCertContext.IsInvalid)
293  {
294  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
295  }
296  if (m_publicKey == null)
297  {
298  string keyAlgorithm = GetKeyAlgorithm();
299  byte[] keyAlgorithmParameters = GetKeyAlgorithmParameters();
300  byte[] publicKey = GetPublicKey();
301  Oid oid = new Oid(keyAlgorithm, System.Security.Cryptography.OidGroup.PublicKeyAlgorithm, lookupFriendlyName: true);
302  m_publicKey = new PublicKey(oid, new AsnEncodedData(oid, keyAlgorithmParameters), new AsnEncodedData(oid, publicKey));
303  }
304  return m_publicKey;
305  }
306  }
307 
310  public byte[] RawData => GetRawCertData();
311 
315 
319  public unsafe X500DistinguishedName SubjectName
320  {
321  get
322  {
323  if (m_safeCertContext.IsInvalid)
324  {
325  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
326  }
327  if (m_subjectName == null)
328  {
329  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)m_safeCertContext.DangerousGetHandle();
330  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
331  m_subjectName = new X500DistinguishedName(cERT_INFO.Subject);
332  }
333  return m_subjectName;
334  }
335  }
336 
340  public Oid SignatureAlgorithm
341  {
342  get
343  {
344  if (m_safeCertContext.IsInvalid)
345  {
346  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
347  }
348  if (m_signatureAlgorithm == null)
349  {
350  m_signatureAlgorithm = GetSignatureAlgorithm(m_safeCertContext);
351  }
352  return m_signatureAlgorithm;
353  }
354  }
355 
358  public string Thumbprint => GetCertHashString();
359 
363  public int Version
364  {
365  get
366  {
367  if (m_safeCertContext.IsInvalid)
368  {
369  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
370  }
371  if (m_version == 0)
372  {
373  m_version = (int)GetVersion(m_safeCertContext);
374  }
375  return m_version;
376  }
377  }
378 
379  internal new System.Security.Cryptography.SafeCertContextHandle CertContext => m_safeCertContext;
380 
383  {
384  }
385 
389  public X509Certificate2(byte[] rawData)
390  : base(rawData)
391  {
392  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
393  }
394 
399  public X509Certificate2(byte[] rawData, string password)
400  : base(rawData, password)
401  {
402  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
403  }
404 
409  public X509Certificate2(byte[] rawData, SecureString password)
410  : base(rawData, password)
411  {
412  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
413  }
414 
420  public X509Certificate2(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
421  : base(rawData, password, keyStorageFlags)
422  {
423  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
424  }
425 
431  public X509Certificate2(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
432  : base(rawData, password, keyStorageFlags)
433  {
434  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
435  }
436 
440  public X509Certificate2(string fileName)
441  : base(fileName)
442  {
443  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
444  }
445 
450  public X509Certificate2(string fileName, string password)
451  : base(fileName, password)
452  {
453  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
454  }
455 
460  public X509Certificate2(string fileName, SecureString password)
461  : base(fileName, password)
462  {
463  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
464  }
465 
471  public X509Certificate2(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
472  : base(fileName, password, keyStorageFlags)
473  {
474  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
475  }
476 
482  public X509Certificate2(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
483  : base(fileName, password, keyStorageFlags)
484  {
485  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
486  }
487 
491  [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
492  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
493  public X509Certificate2(IntPtr handle)
494  : base(handle)
495  {
496  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
497  }
498 
502  public X509Certificate2(X509Certificate certificate)
503  : base(certificate)
504  {
505  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
506  }
507 
511  [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
512  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
514  : base(info, context)
515  {
516  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
517  }
518 
521  public override string ToString()
522  {
523  return base.ToString(fVerbose: true);
524  }
525 
530  public override string ToString(bool verbose)
531  {
532  if (!verbose || m_safeCertContext.IsInvalid)
533  {
534  return ToString();
535  }
536  StringBuilder stringBuilder = new StringBuilder();
537  string newLine = Environment.NewLine;
538  string value = newLine + newLine;
539  string value2 = newLine + " ";
540  stringBuilder.Append("[Version]");
541  stringBuilder.Append(value2);
542  stringBuilder.Append("V" + Version);
543  stringBuilder.Append(value);
544  stringBuilder.Append("[Subject]");
545  stringBuilder.Append(value2);
546  stringBuilder.Append(SubjectName.Name);
547  string nameInfo = GetNameInfo(X509NameType.SimpleName, forIssuer: false);
548  if (nameInfo.Length > 0)
549  {
550  stringBuilder.Append(value2);
551  stringBuilder.Append("Simple Name: ");
552  stringBuilder.Append(nameInfo);
553  }
554  string nameInfo2 = GetNameInfo(X509NameType.EmailName, forIssuer: false);
555  if (nameInfo2.Length > 0)
556  {
557  stringBuilder.Append(value2);
558  stringBuilder.Append("Email Name: ");
559  stringBuilder.Append(nameInfo2);
560  }
561  string nameInfo3 = GetNameInfo(X509NameType.UpnName, forIssuer: false);
562  if (nameInfo3.Length > 0)
563  {
564  stringBuilder.Append(value2);
565  stringBuilder.Append("UPN Name: ");
566  stringBuilder.Append(nameInfo3);
567  }
568  string nameInfo4 = GetNameInfo(X509NameType.DnsName, forIssuer: false);
569  if (nameInfo4.Length > 0)
570  {
571  stringBuilder.Append(value2);
572  stringBuilder.Append("DNS Name: ");
573  stringBuilder.Append(nameInfo4);
574  }
575  stringBuilder.Append(value);
576  stringBuilder.Append("[Issuer]");
577  stringBuilder.Append(value2);
578  stringBuilder.Append(IssuerName.Name);
579  nameInfo = GetNameInfo(X509NameType.SimpleName, forIssuer: true);
580  if (nameInfo.Length > 0)
581  {
582  stringBuilder.Append(value2);
583  stringBuilder.Append("Simple Name: ");
584  stringBuilder.Append(nameInfo);
585  }
586  nameInfo2 = GetNameInfo(X509NameType.EmailName, forIssuer: true);
587  if (nameInfo2.Length > 0)
588  {
589  stringBuilder.Append(value2);
590  stringBuilder.Append("Email Name: ");
591  stringBuilder.Append(nameInfo2);
592  }
593  nameInfo3 = GetNameInfo(X509NameType.UpnName, forIssuer: true);
594  if (nameInfo3.Length > 0)
595  {
596  stringBuilder.Append(value2);
597  stringBuilder.Append("UPN Name: ");
598  stringBuilder.Append(nameInfo3);
599  }
600  nameInfo4 = GetNameInfo(X509NameType.DnsName, forIssuer: true);
601  if (nameInfo4.Length > 0)
602  {
603  stringBuilder.Append(value2);
604  stringBuilder.Append("DNS Name: ");
605  stringBuilder.Append(nameInfo4);
606  }
607  stringBuilder.Append(value);
608  stringBuilder.Append("[Serial Number]");
609  stringBuilder.Append(value2);
610  stringBuilder.Append(SerialNumber);
611  stringBuilder.Append(value);
612  stringBuilder.Append("[Not Before]");
613  stringBuilder.Append(value2);
614  stringBuilder.Append(X509Certificate.FormatDate(NotBefore));
615  stringBuilder.Append(value);
616  stringBuilder.Append("[Not After]");
617  stringBuilder.Append(value2);
618  stringBuilder.Append(X509Certificate.FormatDate(NotAfter));
619  stringBuilder.Append(value);
620  stringBuilder.Append("[Thumbprint]");
621  stringBuilder.Append(value2);
622  stringBuilder.Append(Thumbprint);
623  stringBuilder.Append(value);
624  stringBuilder.Append("[Signature Algorithm]");
625  stringBuilder.Append(value2);
626  stringBuilder.Append(SignatureAlgorithm.FriendlyName + "(" + SignatureAlgorithm.Value + ")");
627  stringBuilder.Append(value);
628  stringBuilder.Append("[Public Key]");
629  try
630  {
631  PublicKey publicKey = PublicKey;
632  string friendlyName = publicKey.Oid.FriendlyName;
633  stringBuilder.Append(value2);
634  stringBuilder.Append("Algorithm: ");
635  stringBuilder.Append(friendlyName);
636  try
637  {
638  friendlyName = publicKey.Key.KeySize.ToString();
639  stringBuilder.Append(value2);
640  stringBuilder.Append("Length: ");
641  stringBuilder.Append(friendlyName);
642  }
643  catch (NotSupportedException)
644  {
645  }
646  friendlyName = publicKey.EncodedKeyValue.Format(multiLine: true);
647  stringBuilder.Append(value2);
648  stringBuilder.Append("Key Blob: ");
649  stringBuilder.Append(friendlyName);
650  friendlyName = publicKey.EncodedParameters.Format(multiLine: true);
651  stringBuilder.Append(value2);
652  stringBuilder.Append("Parameters: ");
653  stringBuilder.Append(friendlyName);
654  }
655  catch (CryptographicException)
656  {
657  }
658  AppendPrivateKeyInfo(stringBuilder);
659  X509ExtensionCollection extensions = Extensions;
660  if (extensions.Count > 0)
661  {
662  stringBuilder.Append(value);
663  stringBuilder.Append("[Extensions]");
664  X509ExtensionEnumerator enumerator = extensions.GetEnumerator();
665  while (enumerator.MoveNext())
666  {
667  X509Extension current = enumerator.Current;
668  try
669  {
670  string friendlyName2 = current.Oid.FriendlyName;
671  stringBuilder.Append(newLine);
672  stringBuilder.Append("* " + friendlyName2);
673  stringBuilder.Append("(" + current.Oid.Value + "):");
674  friendlyName2 = current.Format(multiLine: true);
675  stringBuilder.Append(value2);
676  stringBuilder.Append(friendlyName2);
677  }
678  catch (CryptographicException)
679  {
680  }
681  }
682  }
683  stringBuilder.Append(newLine);
684  return stringBuilder.ToString();
685  }
686 
692  public unsafe string GetNameInfo(X509NameType nameType, bool forIssuer)
693  {
694  uint dwFlags = forIssuer ? 1u : 0u;
695  uint num = System.Security.Cryptography.X509Certificates.X509Utils.MapNameType(nameType);
696  switch (num)
697  {
698  case 4u:
699  return CAPI.GetCertNameInfo(m_safeCertContext, dwFlags, num);
700  case 1u:
701  return CAPI.GetCertNameInfo(m_safeCertContext, dwFlags, num);
702  default:
703  {
704  string text = string.Empty;
705  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)m_safeCertContext.DangerousGetHandle();
706  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
707  IntPtr[] array = new IntPtr[2]
708  {
709  CAPISafe.CertFindExtension(forIssuer ? "2.5.29.8" : "2.5.29.7", cERT_INFO.cExtension, cERT_INFO.rgExtension),
710  CAPISafe.CertFindExtension(forIssuer ? "2.5.29.18" : "2.5.29.17", cERT_INFO.cExtension, cERT_INFO.rgExtension)
711  };
712  for (int i = 0; i < array.Length; i++)
713  {
714  if (!(array[i] != IntPtr.Zero))
715  {
716  continue;
717  }
718  CAPIBase.CERT_EXTENSION cERT_EXTENSION = (CAPIBase.CERT_EXTENSION)Marshal.PtrToStructure(array[i], typeof(CAPIBase.CERT_EXTENSION));
719  byte[] array2 = new byte[cERT_EXTENSION.Value.cbData];
720  Marshal.Copy(cERT_EXTENSION.Value.pbData, array2, 0, array2.Length);
721  uint cbDecodedValue = 0u;
722  SafeLocalAllocHandle decodedValue = null;
723  SafeLocalAllocHandle safeLocalAllocHandle = System.Security.Cryptography.X509Certificates.X509Utils.StringToAnsiPtr(cERT_EXTENSION.pszObjId);
724  bool flag = CAPI.DecodeObject(safeLocalAllocHandle.DangerousGetHandle(), array2, out decodedValue, out cbDecodedValue);
725  safeLocalAllocHandle.Dispose();
726  if (!flag)
727  {
728  continue;
729  }
730  CAPIBase.CERT_ALT_NAME_INFO cERT_ALT_NAME_INFO = (CAPIBase.CERT_ALT_NAME_INFO)Marshal.PtrToStructure(decodedValue.DangerousGetHandle(), typeof(CAPIBase.CERT_ALT_NAME_INFO));
731  for (int j = 0; j < cERT_ALT_NAME_INFO.cAltEntry; j++)
732  {
733  IntPtr ptr = new IntPtr((long)cERT_ALT_NAME_INFO.rgAltEntry + j * Marshal.SizeOf(typeof(CAPIBase.CERT_ALT_NAME_ENTRY)));
734  CAPIBase.CERT_ALT_NAME_ENTRY cERT_ALT_NAME_ENTRY = (CAPIBase.CERT_ALT_NAME_ENTRY)Marshal.PtrToStructure(ptr, typeof(CAPIBase.CERT_ALT_NAME_ENTRY));
735  switch (num)
736  {
737  case 8u:
738  {
739  if (cERT_ALT_NAME_ENTRY.dwAltNameChoice != 1)
740  {
741  break;
742  }
743  CAPIBase.CERT_OTHER_NAME cERT_OTHER_NAME = (CAPIBase.CERT_OTHER_NAME)Marshal.PtrToStructure(cERT_ALT_NAME_ENTRY.Value.pOtherName, typeof(CAPIBase.CERT_OTHER_NAME));
744  if (!(cERT_OTHER_NAME.pszObjId == "1.3.6.1.4.1.311.20.2.3"))
745  {
746  break;
747  }
748  uint cbDecodedValue2 = 0u;
749  SafeLocalAllocHandle decodedValue2 = null;
750  if (CAPI.DecodeObject(new IntPtr(24L), System.Security.Cryptography.X509Certificates.X509Utils.PtrToByte(cERT_OTHER_NAME.Value.pbData, cERT_OTHER_NAME.Value.cbData), out decodedValue2, out cbDecodedValue2))
751  {
752  CAPIBase.CERT_NAME_VALUE cERT_NAME_VALUE = (CAPIBase.CERT_NAME_VALUE)Marshal.PtrToStructure(decodedValue2.DangerousGetHandle(), typeof(CAPIBase.CERT_NAME_VALUE));
753  if (System.Security.Cryptography.X509Certificates.X509Utils.IsCertRdnCharString(cERT_NAME_VALUE.dwValueType))
754  {
755  text = Marshal.PtrToStringUni(cERT_NAME_VALUE.Value.pbData);
756  }
757  decodedValue2.Dispose();
758  }
759  break;
760  }
761  case 6u:
762  if (cERT_ALT_NAME_ENTRY.dwAltNameChoice == 3)
763  {
764  text = Marshal.PtrToStringUni(cERT_ALT_NAME_ENTRY.Value.pwszDNSName);
765  }
766  break;
767  case 7u:
768  if (cERT_ALT_NAME_ENTRY.dwAltNameChoice == 7)
769  {
770  text = Marshal.PtrToStringUni(cERT_ALT_NAME_ENTRY.Value.pwszURL);
771  }
772  break;
773  }
774  }
775  decodedValue.Dispose();
776  }
777  if (nameType == X509NameType.DnsName && (text == null || text.Length == 0))
778  {
779  text = CAPI.GetCertNameInfo(m_safeCertContext, dwFlags, 3u);
780  }
781  return text;
782  }
783  }
784  }
785 
788  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
789  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
790  public override void Import(byte[] rawData)
791  {
792  Reset();
793  base.Import(rawData);
794  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
795  }
796 
801  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
802  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
803  public override void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
804  {
805  Reset();
806  base.Import(rawData, password, keyStorageFlags);
807  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
808  }
809 
814  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
815  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
816  public override void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
817  {
818  Reset();
819  base.Import(rawData, password, keyStorageFlags);
820  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
821  }
822 
825  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
826  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
827  public override void Import(string fileName)
828  {
829  Reset();
830  base.Import(fileName);
831  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
832  }
833 
838  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
839  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
840  public override void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
841  {
842  Reset();
843  base.Import(fileName, password, keyStorageFlags);
844  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
845  }
846 
851  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
852  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
853  public override void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
854  {
855  Reset();
856  base.Import(fileName, password, keyStorageFlags);
857  m_safeCertContext = CAPI.CertDuplicateCertificateContext(base.Handle);
858  }
859 
861  [PermissionSet(SecurityAction.LinkDemand, Unrestricted = true)]
862  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
863  public override void Reset()
864  {
865  m_version = 0;
866  m_notBefore = DateTime.MinValue;
867  m_notAfter = DateTime.MinValue;
868  m_privateKey = null;
869  m_publicKey = null;
870  m_extensions = null;
871  m_signatureAlgorithm = null;
872  m_subjectName = null;
873  m_issuerName = null;
874  if (!m_safeCertContext.IsInvalid)
875  {
876  m_safeCertContext.Dispose();
877  m_safeCertContext = System.Security.Cryptography.SafeCertContextHandle.InvalidHandle;
878  }
879  base.Reset();
880  }
881 
886  public bool Verify()
887  {
888  if (m_safeCertContext.IsInvalid)
889  {
890  throw new CryptographicException(SR.GetString("Cryptography_InvalidHandle"), "m_safeCertContext");
891  }
892  int num = System.Security.Cryptography.X509Certificates.X509Utils.VerifyCertificate(CertContext, null, null, X509RevocationMode.Online, X509RevocationFlag.ExcludeRoot, DateTime.Now, new TimeSpan(0, 0, 0), null, new IntPtr(1L), IntPtr.Zero);
893  return num == 0;
894  }
895 
901  public static X509ContentType GetCertContentType(byte[] rawData)
902  {
903  if (rawData == null || rawData.Length == 0)
904  {
905  throw new ArgumentException(SR.GetString("Arg_EmptyOrNullArray"), "rawData");
906  }
907  uint contentType = QueryCertBlobType(rawData);
908  return System.Security.Cryptography.X509Certificates.X509Utils.MapContentType(contentType);
909  }
910 
916  public static X509ContentType GetCertContentType(string fileName)
917  {
918  if (fileName == null)
919  {
920  throw new ArgumentNullException("fileName");
921  }
922  string fullPath = Path.GetFullPath(fileName);
923  new FileIOPermission(FileIOPermissionAccess.Read, fullPath).Demand();
924  uint contentType = QueryCertFileType(fileName);
925  return System.Security.Cryptography.X509Certificates.X509Utils.MapContentType(contentType);
926  }
927 
928  internal static bool GetPrivateKeyInfo(System.Security.Cryptography.SafeCertContextHandle safeCertContext, ref CspParameters parameters)
929  {
930  SafeLocalAllocHandle invalidHandle = SafeLocalAllocHandle.InvalidHandle;
931  uint pcbData = 0u;
932  if (!CAPISafe.CertGetCertificateContextProperty(safeCertContext, 2u, invalidHandle, ref pcbData))
933  {
934  int lastWin32Error = Marshal.GetLastWin32Error();
935  if (lastWin32Error == -2146885628)
936  {
937  return false;
938  }
940  }
941  invalidHandle = CAPI.LocalAlloc(0u, new IntPtr(pcbData));
942  if (!CAPISafe.CertGetCertificateContextProperty(safeCertContext, 2u, invalidHandle, ref pcbData))
943  {
944  int lastWin32Error2 = Marshal.GetLastWin32Error();
945  if (lastWin32Error2 == -2146885628)
946  {
947  return false;
948  }
949  throw new CryptographicException(Marshal.GetLastWin32Error());
950  }
951  CAPIBase.CRYPT_KEY_PROV_INFO cRYPT_KEY_PROV_INFO = (CAPIBase.CRYPT_KEY_PROV_INFO)Marshal.PtrToStructure(invalidHandle.DangerousGetHandle(), typeof(CAPIBase.CRYPT_KEY_PROV_INFO));
952  parameters.ProviderName = cRYPT_KEY_PROV_INFO.pwszProvName;
953  parameters.KeyContainerName = cRYPT_KEY_PROV_INFO.pwszContainerName;
954  parameters.ProviderType = (int)cRYPT_KEY_PROV_INFO.dwProvType;
955  parameters.KeyNumber = (int)cRYPT_KEY_PROV_INFO.dwKeySpec;
956  parameters.Flags = (((cRYPT_KEY_PROV_INFO.dwFlags & 0x20) == 32) ? CspProviderFlags.UseMachineKeyStore : CspProviderFlags.NoFlags);
957  invalidHandle.Dispose();
958  return true;
959  }
960 
961  private void AppendPrivateKeyInfo(StringBuilder sb)
962  {
963  CspKeyContainerInfo cspKeyContainerInfo = null;
964  try
965  {
966  if (HasPrivateKey)
967  {
968  CspParameters parameters = new CspParameters();
969  if (GetPrivateKeyInfo(m_safeCertContext, ref parameters))
970  {
971  cspKeyContainerInfo = new CspKeyContainerInfo(parameters);
972  }
973  }
974  }
975  catch (SecurityException)
976  {
977  }
978  catch (CryptographicException)
979  {
980  }
981  if (cspKeyContainerInfo != null)
982  {
983  sb.Append(Environment.NewLine + Environment.NewLine + "[Private Key]");
984  sb.Append(Environment.NewLine + " Key Store: ");
985  sb.Append(cspKeyContainerInfo.MachineKeyStore ? "Machine" : "User");
986  sb.Append(Environment.NewLine + " Provider Name: ");
987  sb.Append(cspKeyContainerInfo.ProviderName);
988  sb.Append(Environment.NewLine + " Provider type: ");
989  sb.Append(cspKeyContainerInfo.ProviderType);
990  sb.Append(Environment.NewLine + " Key Spec: ");
991  sb.Append(cspKeyContainerInfo.KeyNumber);
992  sb.Append(Environment.NewLine + " Key Container Name: ");
993  sb.Append(cspKeyContainerInfo.KeyContainerName);
994  try
995  {
996  string uniqueKeyContainerName = cspKeyContainerInfo.UniqueKeyContainerName;
997  sb.Append(Environment.NewLine + " Unique Key Container Name: ");
998  sb.Append(uniqueKeyContainerName);
999  }
1000  catch (CryptographicException)
1001  {
1002  }
1003  catch (NotSupportedException)
1004  {
1005  }
1006  bool flag = false;
1007  try
1008  {
1009  flag = cspKeyContainerInfo.HardwareDevice;
1010  sb.Append(Environment.NewLine + " Hardware Device: ");
1011  sb.Append(flag);
1012  }
1013  catch (CryptographicException)
1014  {
1015  }
1016  try
1017  {
1018  flag = cspKeyContainerInfo.Removable;
1019  sb.Append(Environment.NewLine + " Removable: ");
1020  sb.Append(flag);
1021  }
1022  catch (CryptographicException)
1023  {
1024  }
1025  try
1026  {
1027  flag = cspKeyContainerInfo.Protected;
1028  sb.Append(Environment.NewLine + " Protected: ");
1029  sb.Append(flag);
1030  }
1031  catch (CryptographicException)
1032  {
1033  }
1034  catch (NotSupportedException)
1035  {
1036  }
1037  }
1038  }
1039 
1040  private unsafe static Oid GetSignatureAlgorithm(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
1041  {
1042  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)safeCertContextHandle.DangerousGetHandle();
1043  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
1044  return new Oid(cERT_INFO.SignatureAlgorithm.pszObjId, System.Security.Cryptography.OidGroup.SignatureAlgorithm, lookupFriendlyName: false);
1045  }
1046 
1047  private unsafe static uint GetVersion(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle)
1048  {
1049  CAPIBase.CERT_CONTEXT cERT_CONTEXT = *(CAPIBase.CERT_CONTEXT*)(void*)safeCertContextHandle.DangerousGetHandle();
1050  CAPIBase.CERT_INFO cERT_INFO = (CAPIBase.CERT_INFO)Marshal.PtrToStructure(cERT_CONTEXT.pCertInfo, typeof(CAPIBase.CERT_INFO));
1051  return cERT_INFO.dwVersion + 1;
1052  }
1053 
1054  private unsafe static uint QueryCertBlobType(byte[] rawData)
1055  {
1056  uint result = 0u;
1057  if (!CAPI.CryptQueryObject(2u, rawData, 16382u, 14u, 0u, IntPtr.Zero, new IntPtr(&result), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
1058  {
1059  throw new CryptographicException(Marshal.GetLastWin32Error());
1060  }
1061  return result;
1062  }
1063 
1064  private unsafe static uint QueryCertFileType(string fileName)
1065  {
1066  uint result = 0u;
1067  if (!CAPI.CryptQueryObject(1u, fileName, 16382u, 14u, 0u, IntPtr.Zero, new IntPtr(&result), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero))
1068  {
1069  throw new CryptographicException(Marshal.GetLastWin32Error());
1070  }
1071  return result;
1072  }
1073 
1074  private unsafe static void SetFriendlyNameExtendedProperty(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, string name)
1075  {
1076  SafeLocalAllocHandle safeLocalAllocHandle = System.Security.Cryptography.X509Certificates.X509Utils.StringToUniPtr(name);
1077  using (safeLocalAllocHandle)
1078  {
1079  CAPIBase.CRYPTOAPI_BLOB cRYPTOAPI_BLOB = default(CAPIBase.CRYPTOAPI_BLOB);
1080  cRYPTOAPI_BLOB.cbData = (uint)(2 * (name.Length + 1));
1081  cRYPTOAPI_BLOB.pbData = safeLocalAllocHandle.DangerousGetHandle();
1082  if (!CAPI.CertSetCertificateContextProperty(safeCertContextHandle, 11u, 0u, new IntPtr(&cRYPTOAPI_BLOB)))
1083  {
1084  throw new CryptographicException(Marshal.GetLastWin32Error());
1085  }
1086  }
1087  }
1088 
1089  private static void SetPrivateKeyProperty(System.Security.Cryptography.SafeCertContextHandle safeCertContextHandle, ICspAsymmetricAlgorithm asymmetricAlgorithm)
1090  {
1091  SafeLocalAllocHandle safeLocalAllocHandle = SafeLocalAllocHandle.InvalidHandle;
1092  if (asymmetricAlgorithm != null)
1093  {
1094  CAPIBase.CRYPT_KEY_PROV_INFO cRYPT_KEY_PROV_INFO = default(CAPIBase.CRYPT_KEY_PROV_INFO);
1095  cRYPT_KEY_PROV_INFO.pwszContainerName = asymmetricAlgorithm.CspKeyContainerInfo.KeyContainerName;
1096  cRYPT_KEY_PROV_INFO.pwszProvName = asymmetricAlgorithm.CspKeyContainerInfo.ProviderName;
1097  cRYPT_KEY_PROV_INFO.dwProvType = (uint)asymmetricAlgorithm.CspKeyContainerInfo.ProviderType;
1098  cRYPT_KEY_PROV_INFO.dwFlags = (asymmetricAlgorithm.CspKeyContainerInfo.MachineKeyStore ? 32u : 0u);
1099  cRYPT_KEY_PROV_INFO.cProvParam = 0u;
1100  cRYPT_KEY_PROV_INFO.rgProvParam = IntPtr.Zero;
1101  cRYPT_KEY_PROV_INFO.dwKeySpec = (uint)asymmetricAlgorithm.CspKeyContainerInfo.KeyNumber;
1102  safeLocalAllocHandle = CAPI.LocalAlloc(64u, new IntPtr(Marshal.SizeOf(typeof(CAPIBase.CRYPT_KEY_PROV_INFO))));
1103  Marshal.StructureToPtr((object)cRYPT_KEY_PROV_INFO, safeLocalAllocHandle.DangerousGetHandle(), fDeleteOld: false);
1104  }
1105  try
1106  {
1107  if (!CAPI.CertSetCertificateContextProperty(safeCertContextHandle, 2u, 0u, safeLocalAllocHandle))
1108  {
1109  throw new CryptographicException(Marshal.GetLastWin32Error());
1110  }
1111  }
1112  finally
1113  {
1114  if (!safeLocalAllocHandle.IsInvalid)
1115  {
1116  Marshal.DestroyStructure(safeLocalAllocHandle.DangerousGetHandle(), typeof(CAPIBase.CRYPT_KEY_PROV_INFO));
1117  safeLocalAllocHandle.Dispose();
1118  }
1119  }
1120  }
1121  }
1122 }
The exception that is thrown when an error occurs during a cryptographic operation.
X509Certificate2(byte[] rawData, string password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
virtual string GetSerialNumberString()
Returns the serial number of the X.509v3 certificate as a hexadecimal string.
virtual string GetKeyAlgorithm()
Returns the key algorithm information for this X.509v3 certificate as a string.
static string NewLine
Gets the newline string defined for this environment.
Definition: Environment.cs:449
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
FileIOPermissionAccess
Specifies the type of file access requested.
X509Certificate2(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
unsafe string GetNameInfo(X509NameType nameType, bool forIssuer)
Gets the subject and issuer names from a certificate.
Performs asymmetric encryption and decryption using the implementation of the T:System....
override void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object with information...
Represents Abstract Syntax Notation One (ASN.1)-encoded data.
static DateTime FromFileTime(long fileTime)
Converts the specified Windows file time to an equivalent local time.
Definition: DateTime.cs:1092
bool Archived
Gets or sets a value indicating that an X.509 certificate is archived.
X509Certificate2(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
X509Certificate2(string fileName, string password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
PublicKey PublicKey
Gets a P:System.Security.Cryptography.X509Certificates.X509Certificate2.PublicKey object associated w...
string SerialNumber
Gets the serial number of a certificate.
override string ToString(bool verbose)
Displays an X.509 certificate in text format.
Oid Oid
Gets or sets the T:System.Security.Cryptography.Oid value for an T:System.Security....
Represents a cryptographic object identifier. This class cannot be inherited.
Definition: Oid.cs:6
Supports a simple iteration over a T:System.Security.Cryptography.X509Certificates....
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:109
AsnEncodedData EncodedParameters
Gets the ASN.1-encoded representation of the public key parameters.
Definition: PublicKey.cs:89
X509Certificate2(IntPtr handle)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
Definition: __Canon.cs:3
Represents the distinguished name of an X509 certificate. This class cannot be inherited.
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
Definition: Marshal.cs:159
string Value
Gets or sets the dotted number of the identifier.
Definition: Oid.cs:17
CspProviderFlags
Specifies flags that modify the behavior of the cryptographic service providers (CSP).
override void Import(byte[] rawData)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object with data from a...
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
X509ContentType
Specifies the format of an X.509 certificate.
unsafe DateTime NotAfter
Gets the date in local time after which a certificate is no longer valid.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
Defines methods that allow an T:System.Security.Cryptography.AsymmetricAlgorithm class to enumerate k...
Represents a certificate's public key information. This class cannot be inherited.
Definition: PublicKey.cs:7
AsymmetricAlgorithm PrivateKey
Gets or sets the T:System.Security.Cryptography.AsymmetricAlgorithm object that represents the privat...
X509RevocationMode
Specifies the mode used to check for X509 certificate revocation.
virtual byte [] GetKeyAlgorithmParameters()
Returns the key algorithm parameters for the X.509v3 certificate as an array of bytes.
static X509ContentType GetCertContentType(byte[] rawData)
Indicates the type of certificate contained in a byte array.
Oid Oid
Gets an object identifier (OID) object of the public key.
Definition: PublicKey.cs:81
X509Certificate2(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
unsafe DateTime NotBefore
Gets the date in local time on which a certificate becomes valid.
bool MoveNext()
Advances the enumerator to the next element in the T:System.Security.Cryptography....
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
X509Certificate2(byte[] rawData, SecureString password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
X509ExtensionCollection Extensions
Gets a collection of T:System.Security.Cryptography.X509Certificates.X509Extension objects.
virtual string GetCertHashString()
Returns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.
X509NameType
Specifies the type of name the X509 certificate contains.
Definition: X509NameType.cs:4
X509Certificate2(byte[] rawData)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
static void Copy(int[] source, int startIndex, IntPtr destination, int length)
Copies data from a one-dimensional, managed 32-bit signed integer array to an unmanaged memory pointe...
Definition: Marshal.cs:301
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Represents a collection that can contain many different types of permissions.
string Name
Gets the comma-delimited distinguished name from an X500 certificate.
bool HasPrivateKey
Gets a value that indicates whether an T:System.Security.Cryptography.X509Certificates....
X509Certificate2(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
static void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld)
Marshals data from a managed object to an unmanaged block of memory.
override void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object with information...
Represents text that should be kept confidential, such as by deleting it from computer memory when no...
Definition: SecureString.cs:11
Represents a collection of T:System.Security.Cryptography.X509Certificates.X509Extension objects....
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
X509Certificate2()
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
X509Extension Current
Gets the current element in the T:System.Security.Cryptography.X509Certificates.X509ExtensionCollecti...
static void DestroyStructure(IntPtr ptr, Type structuretype)
Frees all substructures that the specified unmanaged memory block points to.
Represents the abstract base class from which all implementations of asymmetric algorithms must inher...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
override void Import(string fileName)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object with information...
Represents the version number of an assembly, operating system, or the common language runtime....
Definition: Version.cs:11
Contains parameters that are passed to the cryptographic service provider (CSP) that performs cryptog...
Definition: CspParameters.cs:8
static string GetFullPath(string path)
Returns the absolute path for the specified path string.
Definition: Path.cs:446
virtual int KeySize
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
X509Certificate2(X509Certificate certificate)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static X509ContentType GetCertContentType(string fileName)
Indicates the type of certificate contained in a file.
static string FormatDate(DateTime date)
Converts the specified date and time to a string.
The exception that is thrown when one of the arguments provided to a method is not valid.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
Defines a wrapper object to access the cryptographic service provider (CSP) implementation of the T:S...
static unsafe string PtrToStringUni(IntPtr ptr, int len)
Allocates a managed T:System.String and copies a specified number of characters from an unmanaged Uni...
Definition: Marshal.cs:103
bool Verify()
Performs a X.509 chain validation using basic validation policy.
static void PtrToStructure(IntPtr ptr, object structure)
Marshals data from an unmanaged block of memory to a managed object.
Definition: Marshal.cs:1198
X509ExtensionEnumerator GetEnumerator()
Returns an enumerator that can iterate through an T:System.Security.Cryptography.X509Certificates....
Oid SignatureAlgorithm
Gets the algorithm used to create the signature of a certificate.
virtual string Format(bool multiLine)
Returns a formatted version of the Abstract Syntax Notation One (ASN.1)-encoded data as a string.
override void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object using data from ...
virtual byte [] GetRawCertData()
Returns the raw data for the entire X.509v3 certificate as an array of bytes.
virtual byte [] GetPublicKey()
Returns the public key for the X.509v3 certificate as an array of bytes.
unsafe X500DistinguishedName SubjectName
Gets the subject distinguished name from a certificate.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
override void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object using data from ...
int Count
Gets the number of T:System.Security.Cryptography.X509Certificates.X509Extension objects in a T:Syste...
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
override string ToString()
Displays an X.509 certificate in text format.
X509KeyStorageFlags
Defines where and how to import the private key of an X.509 certificate.
string FriendlyName
Gets or sets the associated alias for a certificate.
unsafe X500DistinguishedName IssuerName
Gets the distinguished name of the certificate issuer.
Specifies that the class can be serialized.
string Thumbprint
Gets the thumbprint of a certificate.
static DateTime Now
Gets a T:System.DateTime object that is set to the current date and time on this computer,...
Definition: DateTime.cs:264
X509Certificate2(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
AsymmetricAlgorithm Key
Gets an T:System.Security.Cryptography.RSACryptoServiceProvider or T:System.Security....
Definition: PublicKey.cs:49
The exception that is thrown when an unexpected operation occurs during a cryptographic operation.
AsnEncodedData EncodedKeyValue
Gets the ASN.1-encoded representation of the public key value.
Definition: PublicKey.cs:85
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Controls the ability to access files and folders. This class cannot be inherited.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
SecurityPermissionFlag
Specifies access flags for the security permission object.
X509RevocationFlag
Specifies which X509 certificates in the chain should be checked for revocation.
X509Certificate2(string fileName, SecureString password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
CspKeyContainerInfo CspKeyContainerInfo
Gets a T:System.Security.Cryptography.CspKeyContainerInfo object that describes additional informatio...
byte [] ExportCspBlob(bool includePrivateParameters)
Exports a blob that contains the key information associated with an T:System.Security....
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
Provides methods that help you use X.509 v.3 certificates.
byte [] RawData
Gets the raw data of a certificate.
override void Reset()
Resets the state of an T:System.Security.Cryptography.X509Certificates.X509Certificate2 object.
X509Certificate2(string fileName)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
string FriendlyName
Gets or sets the friendly name of the identifier.
Definition: Oid.cs:31