mscorlib(4.0.0.0) API with additions
X509Certificate.cs
1 using Microsoft.Win32;
3 using System.IO;
8 using System.Security.Util;
9 using System.Text;
10 
12 {
14  [Serializable]
15  [ComVisible(true)]
17  {
18  private const string m_format = "X509";
19 
20  private string m_subjectName;
21 
22  private string m_issuerName;
23 
24  private byte[] m_serialNumber;
25 
26  private byte[] m_publicKeyParameters;
27 
28  private byte[] m_publicKeyValue;
29 
30  private string m_publicKeyOid;
31 
32  private byte[] m_rawData;
33 
34  private byte[] m_thumbprint;
35 
36  private DateTime m_notBefore;
37 
38  private DateTime m_notAfter;
39 
40  [SecurityCritical]
41  private SafeCertContextHandle m_safeCertContext;
42 
43  private bool m_certContextCloned;
44 
47  [ComVisible(false)]
48  public IntPtr Handle
49  {
50  [SecurityCritical]
51  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
52  get
53  {
54  return m_safeCertContext.pCertContext;
55  }
56  }
57 
61  public string Issuer
62  {
63  [SecuritySafeCritical]
64  get
65  {
66  ThrowIfContextInvalid();
67  if (m_issuerName == null)
68  {
69  m_issuerName = X509Utils._GetIssuerName(m_safeCertContext, legacyV1Mode: false);
70  }
71  return m_issuerName;
72  }
73  }
74 
78  public string Subject
79  {
80  [SecuritySafeCritical]
81  get
82  {
83  ThrowIfContextInvalid();
84  if (m_subjectName == null)
85  {
86  m_subjectName = X509Utils._GetSubjectInfo(m_safeCertContext, 2u, legacyV1Mode: false);
87  }
88  return m_subjectName;
89  }
90  }
91 
92  internal SafeCertContextHandle CertContext
93  {
94  [SecurityCritical]
95  get
96  {
97  return m_safeCertContext;
98  }
99  }
100 
101  private DateTime NotAfter
102  {
103  [SecuritySafeCritical]
104  get
105  {
106  ThrowIfContextInvalid();
107  if (m_notAfter == DateTime.MinValue)
108  {
109  Win32Native.FILE_TIME fileTime = default(Win32Native.FILE_TIME);
110  X509Utils._GetDateNotAfter(m_safeCertContext, ref fileTime);
111  m_notAfter = DateTime.FromFileTime(fileTime.ToTicks());
112  }
113  return m_notAfter;
114  }
115  }
116 
117  private DateTime NotBefore
118  {
119  [SecuritySafeCritical]
120  get
121  {
122  ThrowIfContextInvalid();
123  if (m_notBefore == DateTime.MinValue)
124  {
125  Win32Native.FILE_TIME fileTime = default(Win32Native.FILE_TIME);
126  X509Utils._GetDateNotBefore(m_safeCertContext, ref fileTime);
127  m_notBefore = DateTime.FromFileTime(fileTime.ToTicks());
128  }
129  return m_notBefore;
130  }
131  }
132 
133  private byte[] RawData
134  {
135  [SecurityCritical]
136  get
137  {
138  ThrowIfContextInvalid();
139  if (m_rawData == null)
140  {
141  m_rawData = X509Utils._GetCertRawData(m_safeCertContext);
142  }
143  return (byte[])m_rawData.Clone();
144  }
145  }
146 
147  private string SerialNumber
148  {
149  [SecuritySafeCritical]
150  get
151  {
152  ThrowIfContextInvalid();
153  if (m_serialNumber == null)
154  {
155  m_serialNumber = X509Utils._GetSerialNumber(m_safeCertContext);
156  }
157  return Hex.EncodeHexStringFromInt(m_serialNumber);
158  }
159  }
160 
161  [SecuritySafeCritical]
162  private void Init()
163  {
164  m_safeCertContext = SafeCertContextHandle.InvalidHandle;
165  }
166 
169  {
170  Init();
171  }
172 
177  public X509Certificate(byte[] data)
178  : this()
179  {
180  if (data != null && data.Length != 0)
181  {
182  LoadCertificateFromBlob(data, null, X509KeyStorageFlags.DefaultKeySet);
183  }
184  }
185 
191  public X509Certificate(byte[] rawData, string password)
192  : this()
193  {
194  LoadCertificateFromBlob(rawData, password, X509KeyStorageFlags.DefaultKeySet);
195  }
196 
202  public X509Certificate(byte[] rawData, SecureString password)
203  : this()
204  {
205  LoadCertificateFromBlob(rawData, password, X509KeyStorageFlags.DefaultKeySet);
206  }
207 
214  public X509Certificate(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
215  : this()
216  {
217  LoadCertificateFromBlob(rawData, password, keyStorageFlags);
218  }
219 
226  public X509Certificate(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
227  : this()
228  {
229  LoadCertificateFromBlob(rawData, password, keyStorageFlags);
230  }
231 
236  [SecuritySafeCritical]
237  public X509Certificate(string fileName)
238  : this()
239  {
240  LoadCertificateFromFile(fileName, null, X509KeyStorageFlags.DefaultKeySet);
241  }
242 
248  [SecuritySafeCritical]
249  public X509Certificate(string fileName, string password)
250  : this()
251  {
252  LoadCertificateFromFile(fileName, password, X509KeyStorageFlags.DefaultKeySet);
253  }
254 
260  [SecuritySafeCritical]
261  public X509Certificate(string fileName, SecureString password)
262  : this()
263  {
264  LoadCertificateFromFile(fileName, password, X509KeyStorageFlags.DefaultKeySet);
265  }
266 
273  [SecuritySafeCritical]
274  public X509Certificate(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
275  : this()
276  {
277  LoadCertificateFromFile(fileName, password, keyStorageFlags);
278  }
279 
286  [SecuritySafeCritical]
287  public X509Certificate(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
288  : this()
289  {
290  LoadCertificateFromFile(fileName, password, keyStorageFlags);
291  }
292 
297  [SecurityCritical]
298  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
299  public X509Certificate(IntPtr handle)
300  : this()
301  {
302  if (handle == IntPtr.Zero)
303  {
304  throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), "handle");
305  }
306  X509Utils._DuplicateCertContext(handle, ref m_safeCertContext);
307  }
308 
313  [SecuritySafeCritical]
315  : this()
316  {
317  if (cert == null)
318  {
319  throw new ArgumentNullException("cert");
320  }
321  if (cert.m_safeCertContext.pCertContext != IntPtr.Zero)
322  {
323  m_safeCertContext = cert.GetCertContextForCloning();
324  m_certContextCloned = true;
325  }
326  }
327 
333  : this()
334  {
335  byte[] array = (byte[])info.GetValue("RawData", typeof(byte[]));
336  if (array != null)
337  {
338  LoadCertificateFromBlob(array, null, X509KeyStorageFlags.DefaultKeySet);
339  }
340  }
341 
346  public static X509Certificate CreateFromCertFile(string filename)
347  {
348  return new X509Certificate(filename);
349  }
350 
354  public static X509Certificate CreateFromSignedFile(string filename)
355  {
356  return new X509Certificate(filename);
357  }
358 
362  [SecuritySafeCritical]
363  [Obsolete("This method has been deprecated. Please use the Subject property instead. http://go.microsoft.com/fwlink/?linkid=14202")]
364  public virtual string GetName()
365  {
366  ThrowIfContextInvalid();
367  return X509Utils._GetSubjectInfo(m_safeCertContext, 2u, legacyV1Mode: true);
368  }
369 
373  [SecuritySafeCritical]
374  [Obsolete("This method has been deprecated. Please use the Issuer property instead. http://go.microsoft.com/fwlink/?linkid=14202")]
375  public virtual string GetIssuerName()
376  {
377  ThrowIfContextInvalid();
378  return X509Utils._GetIssuerName(m_safeCertContext, legacyV1Mode: true);
379  }
380 
384  [SecuritySafeCritical]
385  public virtual byte[] GetSerialNumber()
386  {
387  ThrowIfContextInvalid();
388  if (m_serialNumber == null)
389  {
390  m_serialNumber = X509Utils._GetSerialNumber(m_safeCertContext);
391  }
392  return (byte[])m_serialNumber.Clone();
393  }
394 
397  public virtual string GetSerialNumberString()
398  {
399  return SerialNumber;
400  }
401 
405  [SecuritySafeCritical]
406  public virtual byte[] GetKeyAlgorithmParameters()
407  {
408  ThrowIfContextInvalid();
409  if (m_publicKeyParameters == null)
410  {
411  m_publicKeyParameters = X509Utils._GetPublicKeyParameters(m_safeCertContext);
412  }
413  return (byte[])m_publicKeyParameters.Clone();
414  }
415 
419  [SecuritySafeCritical]
420  public virtual string GetKeyAlgorithmParametersString()
421  {
422  ThrowIfContextInvalid();
423  return Hex.EncodeHexString(GetKeyAlgorithmParameters());
424  }
425 
429  [SecuritySafeCritical]
430  public virtual string GetKeyAlgorithm()
431  {
432  ThrowIfContextInvalid();
433  if (m_publicKeyOid == null)
434  {
435  m_publicKeyOid = X509Utils._GetPublicKeyOid(m_safeCertContext);
436  }
437  return m_publicKeyOid;
438  }
439 
443  [SecuritySafeCritical]
444  public virtual byte[] GetPublicKey()
445  {
446  ThrowIfContextInvalid();
447  if (m_publicKeyValue == null)
448  {
449  m_publicKeyValue = X509Utils._GetPublicKeyValue(m_safeCertContext);
450  }
451  return (byte[])m_publicKeyValue.Clone();
452  }
453 
456  public virtual string GetPublicKeyString()
457  {
458  return Hex.EncodeHexString(GetPublicKey());
459  }
460 
463  [SecuritySafeCritical]
464  public virtual byte[] GetRawCertData()
465  {
466  return RawData;
467  }
468 
471  public virtual string GetRawCertDataString()
472  {
473  return Hex.EncodeHexString(GetRawCertData());
474  }
475 
478  public virtual byte[] GetCertHash()
479  {
480  SetThumbprint();
481  return (byte[])m_thumbprint.Clone();
482  }
483 
486  public virtual string GetCertHashString()
487  {
488  SetThumbprint();
489  return Hex.EncodeHexString(m_thumbprint);
490  }
491 
494  public virtual string GetEffectiveDateString()
495  {
496  return NotBefore.ToString();
497  }
498 
501  public virtual string GetExpirationDateString()
502  {
503  return NotAfter.ToString();
504  }
505 
510  [ComVisible(false)]
511  public override bool Equals(object obj)
512  {
513  if (!(obj is X509Certificate))
514  {
515  return false;
516  }
517  X509Certificate other = (X509Certificate)obj;
518  return Equals(other);
519  }
520 
525  [SecuritySafeCritical]
526  public virtual bool Equals(X509Certificate other)
527  {
528  if (other == null)
529  {
530  return false;
531  }
532  if (m_safeCertContext.IsInvalid)
533  {
534  return other.m_safeCertContext.IsInvalid;
535  }
536  if (!Issuer.Equals(other.Issuer))
537  {
538  return false;
539  }
540  if (!SerialNumber.Equals(other.SerialNumber))
541  {
542  return false;
543  }
544  return true;
545  }
546 
549  [SecuritySafeCritical]
550  public override int GetHashCode()
551  {
552  if (m_safeCertContext.IsInvalid)
553  {
554  return 0;
555  }
556  SetThumbprint();
557  int num = 0;
558  for (int i = 0; i < m_thumbprint.Length && i < 4; i++)
559  {
560  num = ((num << 8) | m_thumbprint[i]);
561  }
562  return num;
563  }
564 
567  public override string ToString()
568  {
569  return ToString(fVerbose: false);
570  }
571 
576  [SecuritySafeCritical]
577  public virtual string ToString(bool fVerbose)
578  {
579  if (!fVerbose || m_safeCertContext.IsInvalid)
580  {
581  return GetType().FullName;
582  }
583  StringBuilder stringBuilder = new StringBuilder();
584  stringBuilder.Append("[Subject]" + Environment.NewLine + " ");
585  stringBuilder.Append(Subject);
586  stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Issuer]" + Environment.NewLine + " ");
587  stringBuilder.Append(Issuer);
588  stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Serial Number]" + Environment.NewLine + " ");
589  stringBuilder.Append(SerialNumber);
590  stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Not Before]" + Environment.NewLine + " ");
591  stringBuilder.Append(FormatDate(NotBefore));
592  stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Not After]" + Environment.NewLine + " ");
593  stringBuilder.Append(FormatDate(NotAfter));
594  stringBuilder.Append(Environment.NewLine + Environment.NewLine + "[Thumbprint]" + Environment.NewLine + " ");
595  stringBuilder.Append(GetCertHashString());
596  stringBuilder.Append(Environment.NewLine);
597  return stringBuilder.ToString();
598  }
599 
603  protected static string FormatDate(DateTime date)
604  {
605  CultureInfo cultureInfo = CultureInfo.CurrentCulture;
606  if (!cultureInfo.DateTimeFormat.Calendar.IsValidDay(date.Year, date.Month, date.Day, 0))
607  {
608  if (cultureInfo.DateTimeFormat.Calendar is UmAlQuraCalendar)
609  {
610  cultureInfo = (cultureInfo.Clone() as CultureInfo);
611  cultureInfo.DateTimeFormat.Calendar = new HijriCalendar();
612  }
613  else
614  {
615  cultureInfo = CultureInfo.InvariantCulture;
616  }
617  }
618  return date.ToString(cultureInfo);
619  }
620 
623  public virtual string GetFormat()
624  {
625  return "X509";
626  }
627 
631  [SecurityCritical]
632  [ComVisible(false)]
633  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
634  public virtual void Import(byte[] rawData)
635  {
636  Reset();
637  LoadCertificateFromBlob(rawData, null, X509KeyStorageFlags.DefaultKeySet);
638  }
639 
645  [SecurityCritical]
646  [ComVisible(false)]
647  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
648  public virtual void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
649  {
650  Reset();
651  LoadCertificateFromBlob(rawData, password, keyStorageFlags);
652  }
653 
659  [SecurityCritical]
660  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
661  public virtual void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
662  {
663  Reset();
664  LoadCertificateFromBlob(rawData, password, keyStorageFlags);
665  }
666 
670  [SecurityCritical]
671  [ComVisible(false)]
672  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
673  public virtual void Import(string fileName)
674  {
675  Reset();
676  LoadCertificateFromFile(fileName, null, X509KeyStorageFlags.DefaultKeySet);
677  }
678 
684  [SecurityCritical]
685  [ComVisible(false)]
686  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
687  public virtual void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
688  {
689  Reset();
690  LoadCertificateFromFile(fileName, password, keyStorageFlags);
691  }
692 
698  [SecurityCritical]
699  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
700  public virtual void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
701  {
702  Reset();
703  LoadCertificateFromFile(fileName, password, keyStorageFlags);
704  }
705 
710  [SecuritySafeCritical]
711  [ComVisible(false)]
712  public virtual byte[] Export(X509ContentType contentType)
713  {
714  return ExportHelper(contentType, null);
715  }
716 
722  [SecuritySafeCritical]
723  [ComVisible(false)]
724  public virtual byte[] Export(X509ContentType contentType, string password)
725  {
726  return ExportHelper(contentType, password);
727  }
728 
734  [SecuritySafeCritical]
735  public virtual byte[] Export(X509ContentType contentType, SecureString password)
736  {
737  return ExportHelper(contentType, password);
738  }
739 
741  [SecurityCritical]
742  [ComVisible(false)]
743  [PermissionSet(SecurityAction.InheritanceDemand, Unrestricted = true)]
744  public virtual void Reset()
745  {
746  m_subjectName = null;
747  m_issuerName = null;
748  m_serialNumber = null;
749  m_publicKeyParameters = null;
750  m_publicKeyValue = null;
751  m_publicKeyOid = null;
752  m_rawData = null;
753  m_thumbprint = null;
754  m_notBefore = DateTime.MinValue;
755  m_notAfter = DateTime.MinValue;
756  if (!m_safeCertContext.IsInvalid)
757  {
758  if (!m_certContextCloned)
759  {
760  m_safeCertContext.Dispose();
761  }
762  m_safeCertContext = SafeCertContextHandle.InvalidHandle;
763  }
764  m_certContextCloned = false;
765  }
766 
768  public void Dispose()
769  {
770  Dispose(disposing: true);
771  }
772 
776  [SecuritySafeCritical]
777  protected virtual void Dispose(bool disposing)
778  {
779  if (disposing)
780  {
781  Reset();
782  }
783  }
784 
788  [SecurityCritical]
790  {
791  if (m_safeCertContext.IsInvalid)
792  {
793  info.AddValue("RawData", null);
794  }
795  else
796  {
797  info.AddValue("RawData", RawData);
798  }
799  }
800 
803  void IDeserializationCallback.OnDeserialization(object sender)
804  {
805  }
806 
807  [SecurityCritical]
808  internal SafeCertContextHandle GetCertContextForCloning()
809  {
810  m_certContextCloned = true;
811  return m_safeCertContext;
812  }
813 
814  [SecurityCritical]
815  private void ThrowIfContextInvalid()
816  {
817  if (m_safeCertContext.IsInvalid)
818  {
819  throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidHandle"), "m_safeCertContext");
820  }
821  }
822 
823  [SecuritySafeCritical]
824  private void SetThumbprint()
825  {
826  ThrowIfContextInvalid();
827  if (m_thumbprint == null)
828  {
829  m_thumbprint = X509Utils._GetThumbprint(m_safeCertContext);
830  }
831  }
832 
833  [SecurityCritical]
834  private byte[] ExportHelper(X509ContentType contentType, object password)
835  {
836  switch (contentType)
837  {
838  case X509ContentType.Pfx:
839  {
841  keyContainerPermission.Demand();
842  break;
843  }
844  default:
845  throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_InvalidContentType"));
846  case X509ContentType.Cert:
847  case X509ContentType.SerializedCert:
848  break;
849  }
850  IntPtr intPtr = IntPtr.Zero;
851  byte[] array = null;
852  SafeCertStoreHandle safeCertStoreHandle = X509Utils.ExportCertToMemoryStore(this);
854  try
855  {
856  intPtr = X509Utils.PasswordToHGlobalUni(password);
857  array = X509Utils._ExportCertificatesToBlob(safeCertStoreHandle, contentType, intPtr);
858  }
859  finally
860  {
861  if (intPtr != IntPtr.Zero)
862  {
864  }
865  safeCertStoreHandle.Dispose();
866  }
867  if (array == null)
868  {
869  throw new CryptographicException(Environment.GetResourceString("Cryptography_X509_ExportFailed"));
870  }
871  return array;
872  }
873 
874  [SecuritySafeCritical]
875  private void LoadCertificateFromBlob(byte[] rawData, object password, X509KeyStorageFlags keyStorageFlags)
876  {
877  if (rawData == null || rawData.Length == 0)
878  {
879  throw new ArgumentException(Environment.GetResourceString("Arg_EmptyOrNullArray"), "rawData");
880  }
881  X509ContentType x509ContentType = X509Utils.MapContentType(X509Utils._QueryCertBlobType(rawData));
882  if (x509ContentType == X509ContentType.Pfx && (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
883  {
885  keyContainerPermission.Demand();
886  }
887  uint dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
888  IntPtr intPtr = IntPtr.Zero;
890  try
891  {
892  intPtr = X509Utils.PasswordToHGlobalUni(password);
893  X509Utils._LoadCertFromBlob(rawData, intPtr, dwFlags, ((keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != 0) ? true : false, ref m_safeCertContext);
894  }
895  finally
896  {
897  if (intPtr != IntPtr.Zero)
898  {
900  }
901  }
902  }
903 
904  [SecurityCritical]
905  private void LoadCertificateFromFile(string fileName, object password, X509KeyStorageFlags keyStorageFlags)
906  {
907  if (fileName == null)
908  {
909  throw new ArgumentNullException("fileName");
910  }
911  string fullPathInternal = Path.GetFullPathInternal(fileName);
912  new FileIOPermission(FileIOPermissionAccess.Read, fullPathInternal).Demand();
913  X509ContentType x509ContentType = X509Utils.MapContentType(X509Utils._QueryCertFileType(fileName));
914  if (x509ContentType == X509ContentType.Pfx && (keyStorageFlags & X509KeyStorageFlags.PersistKeySet) == X509KeyStorageFlags.PersistKeySet)
915  {
917  keyContainerPermission.Demand();
918  }
919  uint dwFlags = X509Utils.MapKeyStorageFlags(keyStorageFlags);
920  IntPtr intPtr = IntPtr.Zero;
922  try
923  {
924  intPtr = X509Utils.PasswordToHGlobalUni(password);
925  X509Utils._LoadCertFromFile(fileName, intPtr, dwFlags, ((keyStorageFlags & X509KeyStorageFlags.PersistKeySet) != 0) ? true : false, ref m_safeCertContext);
926  }
927  finally
928  {
929  if (intPtr != IntPtr.Zero)
930  {
932  }
933  }
934  }
935  }
936 }
virtual bool Equals(X509Certificate other)
Compares two T:System.Security.Cryptography.X509Certificates.X509Certificate objects for equality.
virtual object Clone()
Creates a copy of the current T:System.Globalization.CultureInfo.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
X509Certificate(byte[] rawData, SecureString 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
virtual string GetPublicKeyString()
Returns the public key for the X.509v3 certificate as a hexadecimal string.
virtual void Import(byte[] rawData)
Populates the T:System.Security.Cryptography.X509Certificates.X509Certificate object with data from a...
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.
X509Certificate(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
FileIOPermissionAccess
Specifies the type of file access requested.
X509Certificate(X509Certificate cert)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
X509Certificate(string fileName)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
static DateTime FromFileTime(long fileTime)
Converts the specified Windows file time to an equivalent local time.
Definition: DateTime.cs:1092
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
virtual void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate object with information ...
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:109
virtual void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
Populates an T:System.Security.Cryptography.X509Certificates.X509Certificate object using data from a...
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
string Issuer
Gets the name of the certificate authority that issued the X.509v3 certificate.
Definition: __Canon.cs:3
string Subject
Gets the subject distinguished name from the certificate.
virtual void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
Populates the T:System.Security.Cryptography.X509Certificates.X509Certificate object with information...
X509Certificate(byte[] rawData, string password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
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.
override string ToString()
Returns a string representation of the current T:System.Security.Cryptography.X509Certificates....
Controls the ability to access key containers. This class cannot be inherited.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
X509Certificate(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
A type representing a date and time value.
virtual string GetName()
Returns the name of the principal to which the certificate was issued.
virtual byte [] GetKeyAlgorithmParameters()
Returns the key algorithm parameters for the X.509v3 certificate as an array of bytes.
X509Certificate()
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
X509Certificate(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
Calendar Calendar
Gets or sets the calendar to use for the current culture.
X509Certificate(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
SecurityAction
Specifies the security actions that can be performed using declarative security.
int Year
Gets the year component of the date represented by this instance.
Definition: DateTime.cs:351
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
static X509Certificate CreateFromSignedFile(string filename)
Creates an X.509v3 certificate from the specified signed file.
virtual string GetFormat()
Returns the name of the format of this X.509v3 certificate.
virtual string GetCertHashString()
Returns the SHA1 hash value for the X.509v3 certificate as a hexadecimal string.
virtual void Import(string fileName)
Populates the T:System.Security.Cryptography.X509Certificates.X509Certificate object with information...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
static X509Certificate CreateFromCertFile(string filename)
Creates an X.509v3 certificate from the specified PKCS7 signed file.
Represents a collection that can contain many different types of permissions.
override string ToString()
Converts the value of the current T:System.DateTime object to its equivalent string representation us...
Definition: DateTime.cs:1526
virtual string GetExpirationDateString()
Returns the expiration date of this X.509v3 certificate.
static void ZeroFreeGlobalAllocUnicode(IntPtr s)
Frees an unmanaged string pointer that was allocated using the M:System.Runtime.InteropServices....
Definition: Marshal.cs:3007
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
void Dispose()
Releases all resources used by the current T:System.Security.Cryptography.X509Certificates....
X509Certificate(string fileName, string password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
X509Certificate(IntPtr handle)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
Represents the Saudi Hijri (Um Al Qura) calendar.
Represents text that should be kept confidential, such as by deleting it from computer memory when no...
Definition: SecureString.cs:11
virtual string GetIssuerName()
Returns the name of the certification authority that issued the X.509v3 certificate.
virtual byte [] Export(X509ContentType contentType)
Exports the current T:System.Security.Cryptography.X509Certificates.X509Certificate object to a byte ...
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
virtual void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
Populates the T:System.Security.Cryptography.X509Certificates.X509Certificate object using data from ...
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
virtual string ToString(bool fVerbose)
Returns a string representation of the current T:System.Security.Cryptography.X509Certificates....
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
KeyContainerPermissionFlags
Specifies the type of key container access allowed.
int Day
Gets the day of the month represented by this instance.
Definition: DateTime.cs:160
virtual byte [] Export(X509ContentType contentType, string password)
Exports the current T:System.Security.Cryptography.X509Certificates.X509Certificate object to a byte ...
virtual string GetRawCertDataString()
Returns the raw data for the entire X.509v3 certificate as a hexadecimal string.
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 ....
virtual void Reset()
Resets the state of the T:System.Security.Cryptography.X509Certificates.X509Certificate2 object.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
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...
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
virtual byte [] Export(X509ContentType contentType, SecureString password)
Exports the current T:System.Security.Cryptography.X509Certificates.X509Certificate object to a byte ...
int Month
Gets the month component of the date represented by this instance.
Definition: DateTime.cs:252
virtual byte [] GetRawCertData()
Returns the raw data for the entire X.509v3 certificate as an array of bytes.
override int GetHashCode()
Returns the hash code for the X.509v3 certificate as an integer.
virtual byte [] GetPublicKey()
Returns the public key for the X.509v3 certificate as an array of bytes.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
virtual DateTimeFormatInfo DateTimeFormat
Gets or sets a T:System.Globalization.DateTimeFormatInfo that defines the culturally appropriate form...
Definition: CultureInfo.cs:563
X509KeyStorageFlags
Defines where and how to import the private key of an X.509 certificate.
Specifies that the class can be serialized.
Represents the Hijri calendar.
X509Certificate(byte[] data)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
override bool Equals(object obj)
Compares two T:System.Security.Cryptography.X509Certificates.X509Certificate objects for equality.
virtual byte [] GetCertHash()
Returns the hash value for the X.509v3 certificate as an array of bytes.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
Controls the ability to access files and folders. This class cannot be inherited.
X509Certificate(string fileName, SecureString password)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
SecurityPermissionFlag
Specifies access flags for the security permission object.
virtual string GetEffectiveDateString()
Returns the effective date of this X.509v3 certificate.
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
Performs operations on T:System.String instances that contain file or directory path information....
Definition: Path.cs:13
virtual void Dispose(bool disposing)
Releases all of the unmanaged resources used by this T:System.Security.Cryptography....
Provides methods that help you use X.509 v.3 certificates.
IntPtr Handle
Gets a handle to a Microsoft Cryptographic API certificate context described by an unmanaged PCCERT_C...
virtual string GetKeyAlgorithmParametersString()
Returns the key algorithm parameters for the X.509v3 certificate as a hexadecimal string.
virtual byte [] GetSerialNumber()
Returns the serial number of the X.509v3 certificate as an array of bytes.
X509Certificate(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
Initializes a new instance of the T:System.Security.Cryptography.X509Certificates....
Provides a set of static methods and properties that provide support for compilers....