using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Text; using Mono.Security.Authenticode; using Mono.Security.X509; namespace System.Security.Cryptography.X509Certificates { /// Provides methods that help you use X.509 v.3 certificates. // Token: 0x020004E1 RID: 1249 [MonoTODO("X509ContentType.SerializedCert isn't supported (anywhere in the class)")] [ComVisible(true)] [Serializable] public class X509Certificate : ISerializable, IDeserializationCallback { // Token: 0x06002E42 RID: 11842 RVA: 0x0009442C File Offset: 0x0009262C internal X509Certificate(byte[] data, bool dates) { if (data != null) { this.Import(data, null, X509KeyStorageFlags.DefaultKeySet); this.hideDates = !dates; } } /// Initializes a new instance of the class defined from a sequence of bytes representing an X.509v3 certificate. /// A byte array containing data from an X.509 certificate. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E43 RID: 11843 RVA: 0x00094458 File Offset: 0x00092658 public X509Certificate(byte[] data) : this(data, true) { } /// Initializes a new instance of the class using a handle to an unmanaged PCCERT_CONTEXT structure. /// A handle to an unmanaged PCCERT_CONTEXT structure. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The handle parameter does not represent a valid PCCERT_CONTEXT structure. // Token: 0x06002E44 RID: 11844 RVA: 0x00094464 File Offset: 0x00092664 public X509Certificate(IntPtr handle) { if (handle == IntPtr.Zero) { throw new ArgumentException("Invalid handle."); } throw new NotSupportedException(); } /// Initializes a new instance of the class using another class. /// A class from which to initialize this class. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The value of the parameter is null. // Token: 0x06002E45 RID: 11845 RVA: 0x00094498 File Offset: 0x00092698 public X509Certificate(X509Certificate cert) { if (cert == null) { throw new ArgumentNullException("cert"); } if (cert != null) { byte[] rawCertData = cert.GetRawCertData(); if (rawCertData != null) { this.x509 = new X509Certificate(rawCertData); } this.hideDates = false; } } /// Initializes a new instance of the class. // Token: 0x06002E46 RID: 11846 RVA: 0x000944E4 File Offset: 0x000926E4 public X509Certificate() { } /// Initializes a new instance of the class using a byte array and a password. /// A byte array containing data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E47 RID: 11847 RVA: 0x000944EC File Offset: 0x000926EC public X509Certificate(byte[] rawData, string password) { this.Import(rawData, password, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using a byte array and a password. /// A byte array that contains data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E48 RID: 11848 RVA: 0x00094500 File Offset: 0x00092700 [MonoTODO("SecureString support is incomplete")] public X509Certificate(byte[] rawData, SecureString password) { this.Import(rawData, password, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using a byte array, a password, and a key storage flag. /// A byte array containing data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// One of the values. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E49 RID: 11849 RVA: 0x00094514 File Offset: 0x00092714 public X509Certificate(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) { this.Import(rawData, password, keyStorageFlags); } /// Initializes a new instance of the class using a byte array, a password, and a key storage flag. /// A byte array that contains data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how to import the private key. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E4A RID: 11850 RVA: 0x00094528 File Offset: 0x00092728 [MonoTODO("SecureString support is incomplete")] public X509Certificate(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(rawData, password, keyStorageFlags); } /// Initializes a new instance of the class using the name of a PKCS7 signed file. /// The name of a PKCS7 signed file. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null. // Token: 0x06002E4B RID: 11851 RVA: 0x0009453C File Offset: 0x0009273C public X509Certificate(string fileName) { this.Import(fileName, null, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using the name of a PKCS7 signed file and a password to access the certificate. /// The name of a PKCS7 signed file. /// The password required to access the X.509 certificate data. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null. // Token: 0x06002E4C RID: 11852 RVA: 0x00094550 File Offset: 0x00092750 public X509Certificate(string fileName, string password) { this.Import(fileName, password, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using a certificate file name and a password. /// The name of a certificate file. /// The password required to access the X.509 certificate data. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null. // Token: 0x06002E4D RID: 11853 RVA: 0x00094564 File Offset: 0x00092764 [MonoTODO("SecureString support is incomplete")] public X509Certificate(string fileName, SecureString password) { this.Import(fileName, password, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using the name of a PKCS7 signed file, a password to access the certificate, and a key storage flag. /// The name of a PKCS7 signed file. /// The password required to access the X.509 certificate data. /// One of the values. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null. // Token: 0x06002E4E RID: 11854 RVA: 0x00094578 File Offset: 0x00092778 public X509Certificate(string fileName, string password, X509KeyStorageFlags keyStorageFlags) { this.Import(fileName, password, keyStorageFlags); } /// Initializes a new instance of the class using a certificate file name, a password, and a key storage flag. /// The name of a certificate file. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how to import the private key. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. /// The parameter is null. // Token: 0x06002E4F RID: 11855 RVA: 0x0009458C File Offset: 0x0009278C [MonoTODO("SecureString support is incomplete")] public X509Certificate(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(fileName, password, keyStorageFlags); } /// Initializes a new instance of the class using a object and a structure. /// A object that describes serialization information. /// A structure that describes how serialization should be performed. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. // Token: 0x06002E50 RID: 11856 RVA: 0x000945A0 File Offset: 0x000927A0 public X509Certificate(SerializationInfo info, StreamingContext context) { byte[] array = (byte[])info.GetValue("RawData", typeof(byte[])); this.Import(array, null, X509KeyStorageFlags.DefaultKeySet); } /// Implements the interface and is called back by the deserialization event when deserialization is complete. /// The source of the deserialization event. // Token: 0x06002E51 RID: 11857 RVA: 0x000945D8 File Offset: 0x000927D8 void IDeserializationCallback.OnDeserialization(object sender) { } /// Gets serialization information with all the data needed to recreate an instance of the current object. /// The object to populate with serialization information. /// The destination context of the serialization. // Token: 0x06002E52 RID: 11858 RVA: 0x000945DC File Offset: 0x000927DC void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("RawData", this.x509.RawData); } // Token: 0x06002E53 RID: 11859 RVA: 0x000945F4 File Offset: 0x000927F4 private string tostr(byte[] data) { if (data != null) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { stringBuilder.Append(data[i].ToString("X2")); } return stringBuilder.ToString(); } return null; } /// Creates an X.509v3 certificate using the name of a PKCS7 signed file. /// The newly created X.509 certificate. /// The path of the PKCS7 signed file from which to create the X.509 certificate. /// The parameter is null. /// /// /// /// // Token: 0x06002E54 RID: 11860 RVA: 0x00094644 File Offset: 0x00092844 public static X509Certificate CreateFromCertFile(string filename) { byte[] array = X509Certificate.Load(filename); return new X509Certificate(array); } /// Creates an X.509v3 certificate from the specified signed file. /// The newly created X.509 certificate. /// The path of the signed file from which to create the X.509 certificate. /// /// /// /// // Token: 0x06002E55 RID: 11861 RVA: 0x00094660 File Offset: 0x00092860 [MonoTODO("Incomplete - minimal validation in this version")] public static X509Certificate CreateFromSignedFile(string filename) { try { AuthenticodeDeformatter authenticodeDeformatter = new AuthenticodeDeformatter(filename); if (authenticodeDeformatter.SigningCertificate != null) { return new X509Certificate(authenticodeDeformatter.SigningCertificate.RawData); } } catch (SecurityException) { throw; } catch (Exception ex) { string text = Locale.GetText("Couldn't extract digital signature from {0}.", new object[] { filename }); throw new COMException(text, ex); } throw new CryptographicException(Locale.GetText("{0} isn't signed.", new object[] { filename })); } // Token: 0x06002E56 RID: 11862 RVA: 0x00094714 File Offset: 0x00092914 private void InitFromHandle(IntPtr handle) { if (handle != IntPtr.Zero) { X509Certificate.CertificateContext certificateContext = (X509Certificate.CertificateContext)Marshal.PtrToStructure(handle, typeof(X509Certificate.CertificateContext)); byte[] array = new byte[certificateContext.cbCertEncoded]; Marshal.Copy(certificateContext.pbCertEncoded, array, 0, (int)certificateContext.cbCertEncoded); this.x509 = new X509Certificate(array); } } /// Compares two objects for equality. /// true if the current object is equal to the object specified by the parameter; otherwise, false. /// An object to compare to the current object. // Token: 0x06002E57 RID: 11863 RVA: 0x00094778 File Offset: 0x00092978 public virtual bool Equals(X509Certificate other) { if (other == null) { return false; } if (other.x509 == null) { if (this.x509 == null) { return true; } throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } else { byte[] rawData = other.x509.RawData; if (rawData == null) { return this.x509 == null || this.x509.RawData == null; } if (this.x509 == null) { return false; } if (this.x509.RawData == null) { return false; } if (rawData.Length == this.x509.RawData.Length) { for (int i = 0; i < rawData.Length; i++) { if (rawData[i] != this.x509.RawData[i]) { return false; } } return true; } return false; } } /// Returns the hash value for the X.509v3 certificate as an array of bytes. /// The hash value for the X.509 certificate. // Token: 0x06002E58 RID: 11864 RVA: 0x00094848 File Offset: 0x00092A48 public virtual byte[] GetCertHash() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } if (this.cachedCertificateHash == null && this.x509 != null) { SHA1 sha = SHA1.Create(); this.cachedCertificateHash = sha.ComputeHash(this.x509.RawData); } return this.cachedCertificateHash; } /// Returns the hash value for the X.509v3 certificate as a hexadecimal string. /// The hexadecimal string representation of the X.509 certificate hash value. // Token: 0x06002E59 RID: 11865 RVA: 0x000948AC File Offset: 0x00092AAC public virtual string GetCertHashString() { return this.tostr(this.GetCertHash()); } /// Returns the effective date of this X.509v3 certificate. /// The effective date for this X.509 certificate. // Token: 0x06002E5A RID: 11866 RVA: 0x000948BC File Offset: 0x00092ABC public virtual string GetEffectiveDateString() { if (this.hideDates) { return null; } if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.ValidFrom.ToLocalTime().ToString(); } /// Returns the expiration date of this X.509v3 certificate. /// The expiration date for this X.509 certificate. // Token: 0x06002E5B RID: 11867 RVA: 0x0009490C File Offset: 0x00092B0C public virtual string GetExpirationDateString() { if (this.hideDates) { return null; } if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.ValidUntil.ToLocalTime().ToString(); } /// Returns the name of the format of this X.509v3 certificate. /// The format of this X.509 certificate. // Token: 0x06002E5C RID: 11868 RVA: 0x0009495C File Offset: 0x00092B5C public virtual string GetFormat() { return "X509"; } /// Returns the hash code for the X.509v3 certificate as an integer. /// The hash code for the X.509 certificate as an integer. // Token: 0x06002E5D RID: 11869 RVA: 0x00094964 File Offset: 0x00092B64 public override int GetHashCode() { if (this.x509 == null) { return 0; } if (this.cachedCertificateHash == null) { this.GetCertHash(); } if (this.cachedCertificateHash != null && this.cachedCertificateHash.Length >= 4) { return ((int)this.cachedCertificateHash[0] << 24) | ((int)this.cachedCertificateHash[1] << 16) | ((int)this.cachedCertificateHash[2] << 8) | (int)this.cachedCertificateHash[3]; } return 0; } /// Returns the name of the certification authority that issued the X.509v3 certificate. /// The name of the certification authority that issued the X.509 certificate. /// An error with the certificate occurs. For example:The certificate file does not exist.The certificate is invalid.The certificate's password is incorrect. // Token: 0x06002E5E RID: 11870 RVA: 0x000949D8 File Offset: 0x00092BD8 [Obsolete("Use the Issuer property.")] public virtual string GetIssuerName() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.IssuerName; } /// Returns the key algorithm information for this X.509v3 certificate. /// The key algorithm information for this X.509 certificate as a string. /// The certificate context is invalid. // Token: 0x06002E5F RID: 11871 RVA: 0x00094A0C File Offset: 0x00092C0C public virtual string GetKeyAlgorithm() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.KeyAlgorithm; } /// Returns the key algorithm parameters for the X.509v3 certificate. /// The key algorithm parameters for the X.509 certificate as an array of bytes. /// The certificate context is invalid. // Token: 0x06002E60 RID: 11872 RVA: 0x00094A40 File Offset: 0x00092C40 public virtual byte[] GetKeyAlgorithmParameters() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } byte[] keyAlgorithmParameters = this.x509.KeyAlgorithmParameters; if (keyAlgorithmParameters == null) { throw new CryptographicException(Locale.GetText("Parameters not part of the certificate")); } return keyAlgorithmParameters; } /// Returns the key algorithm parameters for the X.509v3 certificate. /// The key algorithm parameters for the X.509 certificate as a hexadecimal string. /// The certificate context is invalid. // Token: 0x06002E61 RID: 11873 RVA: 0x00094A8C File Offset: 0x00092C8C public virtual string GetKeyAlgorithmParametersString() { return this.tostr(this.GetKeyAlgorithmParameters()); } /// Returns the name of the principal to which the certificate was issued. /// The name of the principal to which the certificate was issued. /// The certificate context is invalid. // Token: 0x06002E62 RID: 11874 RVA: 0x00094A9C File Offset: 0x00092C9C [Obsolete("Use the Subject property.")] public virtual string GetName() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.SubjectName; } /// Returns the public key for the X.509v3 certificate. /// The public key for the X.509 certificate as an array of bytes. /// The certificate context is invalid. // Token: 0x06002E63 RID: 11875 RVA: 0x00094AD0 File Offset: 0x00092CD0 public virtual byte[] GetPublicKey() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.PublicKey; } /// Returns the public key for the X.509v3 certificate. /// The public key for the X.509 certificate as a hexadecimal string. // Token: 0x06002E64 RID: 11876 RVA: 0x00094B04 File Offset: 0x00092D04 public virtual string GetPublicKeyString() { return this.tostr(this.GetPublicKey()); } /// Returns the raw data for the entire X.509v3 certificate. /// A byte array containing the X.509 certificate data. // Token: 0x06002E65 RID: 11877 RVA: 0x00094B14 File Offset: 0x00092D14 public virtual byte[] GetRawCertData() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.RawData; } /// Returns the raw data for the entire X.509v3 certificate. /// The X.509 certificate data as a hexadecimal string. // Token: 0x06002E66 RID: 11878 RVA: 0x00094B48 File Offset: 0x00092D48 public virtual string GetRawCertDataString() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.tostr(this.x509.RawData); } /// Returns the serial number of the X.509v3 certificate. /// The serial number of the X.509 certificate as an array of bytes. /// The certificate context is invalid. // Token: 0x06002E67 RID: 11879 RVA: 0x00094B84 File Offset: 0x00092D84 public virtual byte[] GetSerialNumber() { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } return this.x509.SerialNumber; } /// Returns the serial number of the X.509v3 certificate. /// The serial number of the X.509 certificate as a hexadecimal string. // Token: 0x06002E68 RID: 11880 RVA: 0x00094BB8 File Offset: 0x00092DB8 public virtual string GetSerialNumberString() { byte[] serialNumber = this.GetSerialNumber(); Array.Reverse(serialNumber); return this.tostr(serialNumber); } /// Returns a string representation of the current object. /// A string representation of the current object. // Token: 0x06002E69 RID: 11881 RVA: 0x00094BDC File Offset: 0x00092DDC public override string ToString() { return base.ToString(); } /// Returns a string representation of the current object, with extra information, if specified. /// A string representation of the current object. /// true to produce the verbose form of the string representation; otherwise, false. // Token: 0x06002E6A RID: 11882 RVA: 0x00094BE4 File Offset: 0x00092DE4 public virtual string ToString(bool fVerbose) { if (!fVerbose || this.x509 == null) { return base.ToString(); } string newLine = Environment.NewLine; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("[Subject]{0} {1}{0}{0}", newLine, this.Subject); stringBuilder.AppendFormat("[Issuer]{0} {1}{0}{0}", newLine, this.Issuer); stringBuilder.AppendFormat("[Not Before]{0} {1}{0}{0}", newLine, this.GetEffectiveDateString()); stringBuilder.AppendFormat("[Not After]{0} {1}{0}{0}", newLine, this.GetExpirationDateString()); stringBuilder.AppendFormat("[Thumbprint]{0} {1}{0}", newLine, this.GetCertHashString()); stringBuilder.Append(newLine); return stringBuilder.ToString(); } // Token: 0x06002E6B RID: 11883 RVA: 0x00094C84 File Offset: 0x00092E84 private static byte[] Load(string fileName) { byte[] array = null; using (FileStream fileStream = File.OpenRead(fileName)) { array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); fileStream.Close(); } return array; } /// Gets the name of the certificate authority that issued the X.509v3 certificate. /// The name of the certificate authority that issued the X.509v3 certificate. /// The certificate handle is invalid. // Token: 0x17000927 RID: 2343 // (get) Token: 0x06002E6C RID: 11884 RVA: 0x00094CE8 File Offset: 0x00092EE8 public string Issuer { get { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } if (this.issuer_name == null) { this.issuer_name = X501.ToString(this.x509.GetIssuerName(), true, ", ", true); } return this.issuer_name; } } /// Gets the subject distinguished name from the certificate. /// The subject distinguished name from the certificate. /// The certificate handle is invalid. // Token: 0x17000928 RID: 2344 // (get) Token: 0x06002E6D RID: 11885 RVA: 0x00094D40 File Offset: 0x00092F40 public string Subject { get { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } if (this.subject_name == null) { this.subject_name = X501.ToString(this.x509.GetSubjectName(), true, ", ", true); } return this.subject_name; } } /// Gets a handle to a Microsoft Cryptographic API certificate context described by an unmanaged PCCERT_CONTEXT structure. /// An structure that represents an unmanaged PCCERT_CONTEXT structure. /// /// /// // Token: 0x17000929 RID: 2345 // (get) Token: 0x06002E6E RID: 11886 RVA: 0x00094D98 File Offset: 0x00092F98 [ComVisible(false)] public IntPtr Handle { get { return IntPtr.Zero; } } /// Compares two objects for equality. /// true if the current object is equal to the object specified by the parameter; otherwise, false. /// An object to compare to the current object. // Token: 0x06002E6F RID: 11887 RVA: 0x00094DA0 File Offset: 0x00092FA0 [ComVisible(false)] public override bool Equals(object obj) { X509Certificate x509Certificate = obj as X509Certificate; return x509Certificate != null && this.Equals(x509Certificate); } /// Exports the current object to a byte array in a format described by one of the values. /// An array of bytes that represents the current object. /// One of the values that describes how to format the output data. /// A value other than , , or was passed to the parameter.-or-The certificate could not be exported. /// /// /// // Token: 0x06002E70 RID: 11888 RVA: 0x00094DC4 File Offset: 0x00092FC4 [ComVisible(false)] [MonoTODO("X509ContentType.Pfx/Pkcs12 and SerializedCert are not supported")] public virtual byte[] Export(X509ContentType contentType) { return this.Export(contentType, null); } /// Exports the current object to a byte array in a format described by one of the values, and using the specified password. /// An array of bytes that represents the current object. /// One of the values that describes how to format the output data. /// The password required to access the X.509 certificate data. /// A value other than , , or was passed to the parameter.-or-The certificate could not be exported. /// /// /// // Token: 0x06002E71 RID: 11889 RVA: 0x00094DD0 File Offset: 0x00092FD0 [ComVisible(false)] [MonoTODO("X509ContentType.Pfx/Pkcs12 and SerializedCert are not supported")] public virtual byte[] Export(X509ContentType contentType, string password) { byte[] array = ((password != null) ? Encoding.UTF8.GetBytes(password) : null); return this.Export(contentType, array); } /// Exports the current object to a byte array using the specified format and a password. /// A byte array that represents the current object. /// One of the values that describes how to format the output data. /// The password required to access the X.509 certificate data. /// A value other than , , or was passed to the parameter.-or-The certificate could not be exported. // Token: 0x06002E72 RID: 11890 RVA: 0x00094E00 File Offset: 0x00093000 [MonoTODO("X509ContentType.Pfx/Pkcs12 and SerializedCert are not supported. SecureString support is incomplete.")] public virtual byte[] Export(X509ContentType contentType, SecureString password) { byte[] array = ((password != null) ? password.GetBuffer() : null); return this.Export(contentType, array); } // Token: 0x06002E73 RID: 11891 RVA: 0x00094E28 File Offset: 0x00093028 internal byte[] Export(X509ContentType contentType, byte[] password) { if (this.x509 == null) { throw new CryptographicException(Locale.GetText("Certificate instance is empty.")); } byte[] rawData; try { switch (contentType) { case X509ContentType.Cert: rawData = this.x509.RawData; break; case X509ContentType.SerializedCert: throw new NotSupportedException(); case X509ContentType.Pfx: throw new NotSupportedException(); default: { string text = Locale.GetText("This certificate format '{0}' cannot be exported.", new object[] { contentType }); throw new CryptographicException(text); } } } finally { if (password != null) { Array.Clear(password, 0, password.Length); } } return rawData; } /// Populates the object with data from a byte array. /// A byte array containing data from an X.509 certificate. /// The parameter is null.-or-The length of the parameter is 0. /// /// /// /// // Token: 0x06002E74 RID: 11892 RVA: 0x00094EDC File Offset: 0x000930DC [ComVisible(false)] public virtual void Import(byte[] rawData) { this.Import(rawData, null, X509KeyStorageFlags.DefaultKeySet); } /// Populates the object using data from a byte array, a password, and flags for determining how the private key is imported. /// A byte array containing data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how the private key is imported. /// The parameter is null.-or-The length of the parameter is 0. /// /// /// /// // Token: 0x06002E75 RID: 11893 RVA: 0x00094EE8 File Offset: 0x000930E8 [MonoTODO("missing KeyStorageFlags support")] [ComVisible(false)] public virtual void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) { this.Reset(); if (password == null) { try { this.x509 = new X509Certificate(rawData); } catch (Exception ex) { try { PKCS12 pkcs = new PKCS12(rawData); if (pkcs.Certificates.Count > 0) { this.x509 = pkcs.Certificates[0]; } else { this.x509 = null; } } catch { string text = Locale.GetText("Unable to decode certificate."); throw new CryptographicException(text, ex); } } } else { try { PKCS12 pkcs2 = new PKCS12(rawData, password); if (pkcs2.Certificates.Count > 0) { this.x509 = pkcs2.Certificates[0]; } else { this.x509 = null; } } catch { this.x509 = new X509Certificate(rawData); } } } /// Populates an object using data from a byte array, a password, and a key storage flag. /// A byte array that contains data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how to import the private key. /// The parameter is null.-or-The length of the parameter is 0. // Token: 0x06002E76 RID: 11894 RVA: 0x0009500C File Offset: 0x0009320C [MonoTODO("SecureString support is incomplete")] public virtual void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(rawData, null, keyStorageFlags); } /// Populates the object with information from a certificate file. /// The name of a certificate file represented as a string. /// The parameter is null. /// /// /// /// // Token: 0x06002E77 RID: 11895 RVA: 0x00095018 File Offset: 0x00093218 [ComVisible(false)] public virtual void Import(string fileName) { byte[] array = X509Certificate.Load(fileName); this.Import(array, null, X509KeyStorageFlags.DefaultKeySet); } /// Populates the object with information from a certificate file, a password, and a value. /// The name of a certificate file represented as a string. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how the private key is imported. /// The parameter is null. /// /// /// /// // Token: 0x06002E78 RID: 11896 RVA: 0x00095038 File Offset: 0x00093238 [ComVisible(false)] [MonoTODO("missing KeyStorageFlags support")] public virtual void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags) { byte[] array = X509Certificate.Load(fileName); this.Import(array, password, keyStorageFlags); } /// Populates an object with information from a certificate file, a password, and a key storage flag. /// The name of a certificate file. /// The password required to access the X.509 certificate data. /// One of the values that controls where and how to import the private key. /// The parameter is null. // Token: 0x06002E79 RID: 11897 RVA: 0x00095058 File Offset: 0x00093258 [MonoTODO("SecureString support is incomplete, missing KeyStorageFlags support")] public virtual void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags) { byte[] array = X509Certificate.Load(fileName); this.Import(array, null, keyStorageFlags); } /// Resets the state of the object. // Token: 0x06002E7A RID: 11898 RVA: 0x00095078 File Offset: 0x00093278 [ComVisible(false)] public virtual void Reset() { this.x509 = null; this.issuer_name = null; this.subject_name = null; this.hideDates = false; this.cachedCertificateHash = null; } // Token: 0x0400124D RID: 4685 private X509Certificate x509; // Token: 0x0400124E RID: 4686 private bool hideDates; // Token: 0x0400124F RID: 4687 private byte[] cachedCertificateHash; // Token: 0x04001250 RID: 4688 private string issuer_name; // Token: 0x04001251 RID: 4689 private string subject_name; // Token: 0x020004E2 RID: 1250 internal struct CertificateContext { // Token: 0x04001252 RID: 4690 public uint dwCertEncodingType; // Token: 0x04001253 RID: 4691 public IntPtr pbCertEncoded; // Token: 0x04001254 RID: 4692 public uint cbCertEncoded; // Token: 0x04001255 RID: 4693 public IntPtr pCertInfo; // Token: 0x04001256 RID: 4694 public IntPtr hCertStore; } } }