using System; using System.IO; using System.Text; using Mono.Security; using Mono.Security.Cryptography; using Mono.Security.X509; namespace System.Security.Cryptography.X509Certificates { /// Represents an X.509 certificate. This class can be inherited. // Token: 0x02000288 RID: 648 public class X509Certificate2 : X509Certificate { /// Initializes a new instance of the class. // Token: 0x0600179D RID: 6045 RVA: 0x0004F280 File Offset: 0x0004D480 public X509Certificate2() { this._cert = null; } /// Initializes a new instance of the class using information from a byte array. /// 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. // Token: 0x0600179E RID: 6046 RVA: 0x0004F29C File Offset: 0x0004D49C public X509Certificate2(byte[] rawData) { this.Import(rawData, null, X509KeyStorageFlags.DefaultKeySet); } /// 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. // Token: 0x0600179F RID: 6047 RVA: 0x0004F2B8 File Offset: 0x0004D4B8 public X509Certificate2(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. // Token: 0x060017A0 RID: 6048 RVA: 0x0004F2D4 File Offset: 0x0004D4D4 public X509Certificate2(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. // Token: 0x060017A1 RID: 6049 RVA: 0x0004F2F0 File Offset: 0x0004D4F0 public X509Certificate2(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. // Token: 0x060017A2 RID: 6050 RVA: 0x0004F30C File Offset: 0x0004D50C public X509Certificate2(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(rawData, password, keyStorageFlags); } /// Initializes a new instance of the class using a certificate file name. /// The name of a certificate 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. // Token: 0x060017A3 RID: 6051 RVA: 0x0004F328 File Offset: 0x0004D528 public X509Certificate2(string fileName) { this.Import(fileName, string.Empty, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using a certificate file name and a password used to access the certificate. /// 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. // Token: 0x060017A4 RID: 6052 RVA: 0x0004F348 File Offset: 0x0004D548 public X509Certificate2(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. // Token: 0x060017A5 RID: 6053 RVA: 0x0004F364 File Offset: 0x0004D564 public X509Certificate2(string fileName, SecureString password) { this.Import(fileName, password, X509KeyStorageFlags.DefaultKeySet); } /// Initializes a new instance of the class using a certificate file name, a password used to access the certificate, 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. /// 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: 0x060017A6 RID: 6054 RVA: 0x0004F380 File Offset: 0x0004D580 public X509Certificate2(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. // Token: 0x060017A7 RID: 6055 RVA: 0x0004F39C File Offset: 0x0004D59C public X509Certificate2(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(fileName, password, keyStorageFlags); } /// Initializes a new instance of the class using an unmanaged handle. /// A pointer to a certificate context in unmanaged code. The C structure is called PCCERT_CONTEXT. /// 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: 0x060017A8 RID: 6056 RVA: 0x0004F3B8 File Offset: 0x0004D5B8 public X509Certificate2(IntPtr handle) : base(handle) { this._cert = new X509Certificate(base.GetRawCertData()); } /// Initializes a new instance of the class using an object. /// An object. /// 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: 0x060017A9 RID: 6057 RVA: 0x0004F3E0 File Offset: 0x0004D5E0 public X509Certificate2(X509Certificate certificate) : base(certificate) { this._cert = new X509Certificate(base.GetRawCertData()); } /// Gets or sets a value indicating that an X.509 certificate is archived. /// true if the certificate is archived, false if the certificate is not archived. /// The certificate is unreadable. // Token: 0x17000777 RID: 1911 // (get) Token: 0x060017AB RID: 6059 RVA: 0x0004F46C File Offset: 0x0004D66C // (set) Token: 0x060017AC RID: 6060 RVA: 0x0004F48C File Offset: 0x0004D68C public bool Archived { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return this._archived; } set { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } this._archived = value; } } /// Gets a collection of objects. /// An object. /// The certificate is unreadable. // Token: 0x17000778 RID: 1912 // (get) Token: 0x060017AD RID: 6061 RVA: 0x0004F4AC File Offset: 0x0004D6AC public X509ExtensionCollection Extensions { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this._extensions == null) { this._extensions = new X509ExtensionCollection(this._cert); } return this._extensions; } } /// Gets or sets the associated alias for a certificate. /// The certificate's friendly name. /// The certificate is unreadable. // Token: 0x17000779 RID: 1913 // (get) Token: 0x060017AE RID: 6062 RVA: 0x0004F4F4 File Offset: 0x0004D6F4 // (set) Token: 0x060017AF RID: 6063 RVA: 0x0004F514 File Offset: 0x0004D714 public string FriendlyName { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return this._name; } set { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } this._name = value; } } /// Gets a value that indicates whether an object contains a private key. /// true if the object contains a private key; otherwise, false. /// The certificate context is invalid. // Token: 0x1700077A RID: 1914 // (get) Token: 0x060017B0 RID: 6064 RVA: 0x0004F534 File Offset: 0x0004D734 public bool HasPrivateKey { get { return this.PrivateKey != null; } } /// Gets the distinguished name of the certificate issuer. /// An object that contains the name of the certificate issuer. /// The certificate context is invalid. // Token: 0x1700077B RID: 1915 // (get) Token: 0x060017B1 RID: 6065 RVA: 0x0004F544 File Offset: 0x0004D744 public X500DistinguishedName IssuerName { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this.issuer_name == null) { this.issuer_name = new X500DistinguishedName(this._cert.GetIssuerName().GetBytes()); } return this.issuer_name; } } /// Gets the date in local time after which a certificate is no longer valid. /// A object that represents the expiration date for the certificate . /// The certificate is unreadable. // Token: 0x1700077C RID: 1916 // (get) Token: 0x060017B2 RID: 6066 RVA: 0x0004F594 File Offset: 0x0004D794 public DateTime NotAfter { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return this._cert.ValidUntil.ToLocalTime(); } } /// Gets the date in local time on which a certificate becomes valid. /// A object that represents the effective date of the certificate. /// The certificate is unreadable. // Token: 0x1700077D RID: 1917 // (get) Token: 0x060017B3 RID: 6067 RVA: 0x0004F5CC File Offset: 0x0004D7CC public DateTime NotBefore { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return this._cert.ValidFrom.ToLocalTime(); } } /// Gets or sets the object that represents the private key associated with a certificate. /// An object, which is either an RSA or DSA cryptographic service provider. /// The key value is not an RSA or DSA key, or the key is unreadable. /// The value being set for this property is null. /// The key algorithm for this private key is not supported. /// The X.509 keys do not match. /// The cryptographic service provider key is null. // Token: 0x1700077E RID: 1918 // (get) Token: 0x060017B4 RID: 6068 RVA: 0x0004F604 File Offset: 0x0004D804 // (set) Token: 0x060017B5 RID: 6069 RVA: 0x0004F744 File Offset: 0x0004D944 public AsymmetricAlgorithm PrivateKey { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } try { if (this._cert.RSA != null) { RSACryptoServiceProvider rsacryptoServiceProvider = this._cert.RSA as RSACryptoServiceProvider; if (rsacryptoServiceProvider != null) { return (!rsacryptoServiceProvider.PublicOnly) ? rsacryptoServiceProvider : null; } RSAManaged rsamanaged = this._cert.RSA as RSAManaged; if (rsamanaged != null) { return (!rsamanaged.PublicOnly) ? rsamanaged : null; } this._cert.RSA.ExportParameters(true); return this._cert.RSA; } else if (this._cert.DSA != null) { DSACryptoServiceProvider dsacryptoServiceProvider = this._cert.DSA as DSACryptoServiceProvider; if (dsacryptoServiceProvider != null) { return (!dsacryptoServiceProvider.PublicOnly) ? dsacryptoServiceProvider : null; } this._cert.DSA.ExportParameters(true); return this._cert.DSA; } } catch { } return null; } set { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (value == null) { this._cert.RSA = null; this._cert.DSA = null; } else if (value is RSA) { this._cert.RSA = (RSA)value; } else { if (!(value is DSA)) { throw new NotSupportedException(); } this._cert.DSA = (DSA)value; } } } /// Gets a object associated with a certificate. /// A object. /// The key value is not an RSA or DSA key, or the key is unreadable. // Token: 0x1700077F RID: 1919 // (get) Token: 0x060017B6 RID: 6070 RVA: 0x0004F7D4 File Offset: 0x0004D9D4 public PublicKey PublicKey { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this._publicKey == null) { try { this._publicKey = new PublicKey(this._cert); } catch (Exception ex) { string text = global::Locale.GetText("Unable to decode public key."); throw new CryptographicException(text, ex); } } return this._publicKey; } } /// Gets the raw data of a certificate. /// The raw data of the certificate as a byte array. // Token: 0x17000780 RID: 1920 // (get) Token: 0x060017B7 RID: 6071 RVA: 0x0004F854 File Offset: 0x0004DA54 public byte[] RawData { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return base.GetRawCertData(); } } /// Gets the serial number of a certificate. /// The serial number of the certificate. // Token: 0x17000781 RID: 1921 // (get) Token: 0x060017B8 RID: 6072 RVA: 0x0004F874 File Offset: 0x0004DA74 public string SerialNumber { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this._serial == null) { StringBuilder stringBuilder = new StringBuilder(); byte[] serialNumber = this._cert.SerialNumber; for (int i = serialNumber.Length - 1; i >= 0; i--) { stringBuilder.Append(serialNumber[i].ToString("X2")); } this._serial = stringBuilder.ToString(); } return this._serial; } } /// Gets the algorithm used to create the signature of a certificate. /// Returns the object identifier () of the signature algorithm. /// The certificate is unreadable. // Token: 0x17000782 RID: 1922 // (get) Token: 0x060017B9 RID: 6073 RVA: 0x0004F8F4 File Offset: 0x0004DAF4 public Oid SignatureAlgorithm { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this.signature_algorithm == null) { this.signature_algorithm = new Oid(this._cert.SignatureAlgorithm); } return this.signature_algorithm; } } /// Gets the subject distinguished name from a certificate. /// An object that represents the name of the certificate subject. /// The certificate context is invalid. // Token: 0x17000783 RID: 1923 // (get) Token: 0x060017BA RID: 6074 RVA: 0x0004F934 File Offset: 0x0004DB34 public X500DistinguishedName SubjectName { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } if (this.subject_name == null) { this.subject_name = new X500DistinguishedName(this._cert.GetSubjectName().GetBytes()); } return this.subject_name; } } /// Gets the thumbprint of a certificate. /// The thumbprint of the certificate. // Token: 0x17000784 RID: 1924 // (get) Token: 0x060017BB RID: 6075 RVA: 0x0004F984 File Offset: 0x0004DB84 public string Thumbprint { get { return base.GetCertHashString(); } } /// Gets the X.509 format version of a certificate. /// The certificate format. /// The certificate is unreadable. // Token: 0x17000785 RID: 1925 // (get) Token: 0x060017BC RID: 6076 RVA: 0x0004F98C File Offset: 0x0004DB8C public int Version { get { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } return this._cert.Version; } } /// Gets the subject and issuer names from a certificate. /// The name of the certificate. /// The value for the subject. /// true to include the issuer name; otherwise, false. // Token: 0x060017BD RID: 6077 RVA: 0x0004F9B0 File Offset: 0x0004DBB0 [global::System.MonoTODO("always return String.Empty for UpnName, DnsFromAlternativeName and UrlName")] public string GetNameInfo(X509NameType nameType, bool forIssuer) { switch (nameType) { case X509NameType.SimpleName: { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } ASN1 asn = ((!forIssuer) ? this._cert.GetSubjectName() : this._cert.GetIssuerName()); ASN1 asn2 = this.Find(X509Certificate2.commonName, asn); if (asn2 != null) { return this.GetValueAsString(asn2); } if (asn.Count == 0) { return string.Empty; } ASN1 asn3 = asn[asn.Count - 1]; if (asn3.Count == 0) { return string.Empty; } return this.GetValueAsString(asn3[0]); } case X509NameType.EmailName: { ASN1 asn4 = this.Find(X509Certificate2.email, (!forIssuer) ? this._cert.GetSubjectName() : this._cert.GetIssuerName()); if (asn4 != null) { return this.GetValueAsString(asn4); } return string.Empty; } case X509NameType.UpnName: return string.Empty; case X509NameType.DnsName: { ASN1 asn5 = this.Find(X509Certificate2.commonName, (!forIssuer) ? this._cert.GetSubjectName() : this._cert.GetIssuerName()); if (asn5 != null) { return this.GetValueAsString(asn5); } return string.Empty; } case X509NameType.DnsFromAlternativeName: return string.Empty; case X509NameType.UrlName: return string.Empty; default: throw new ArgumentException("nameType"); } } // Token: 0x060017BE RID: 6078 RVA: 0x0004FB18 File Offset: 0x0004DD18 private ASN1 Find(byte[] oid, ASN1 dn) { if (dn.Count == 0) { return null; } for (int i = 0; i < dn.Count; i++) { ASN1 asn = dn[i]; for (int j = 0; j < asn.Count; j++) { ASN1 asn2 = asn[j]; if (asn2.Count == 2) { ASN1 asn3 = asn2[0]; if (asn3 != null) { if (asn3.CompareValue(oid)) { return asn2; } } } } } return null; } // Token: 0x060017BF RID: 6079 RVA: 0x0004FBA8 File Offset: 0x0004DDA8 private string GetValueAsString(ASN1 pair) { if (pair.Count != 2) { return string.Empty; } ASN1 asn = pair[1]; if (asn.Value == null || asn.Length == 0) { return string.Empty; } if (asn.Tag == 30) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 1; i < asn.Value.Length; i += 2) { stringBuilder.Append((char)asn.Value[i]); } return stringBuilder.ToString(); } return Encoding.UTF8.GetString(asn.Value); } // Token: 0x060017C0 RID: 6080 RVA: 0x0004FC40 File Offset: 0x0004DE40 private void ImportPkcs12(byte[] rawData, string password) { PKCS12 pkcs = ((password != null) ? new PKCS12(rawData, password) : new PKCS12(rawData)); if (pkcs.Certificates.Count > 0) { this._cert = pkcs.Certificates[0]; } else { this._cert = null; } if (pkcs.Keys.Count > 0) { this._cert.RSA = pkcs.Keys[0] as RSA; this._cert.DSA = pkcs.Keys[0] as DSA; } } /// Populates an object with data from a byte array. /// A byte array containing data from an X.509 certificate. // Token: 0x060017C1 RID: 6081 RVA: 0x0004FCE0 File Offset: 0x0004DEE0 public override void Import(byte[] rawData) { this.Import(rawData, null, X509KeyStorageFlags.DefaultKeySet); } /// Populates an object using data from a byte array, a password, and flags for determining how to import the private key. /// A byte array containing data from an X.509 certificate. /// The password required to access the X.509 certificate data. /// One of the values used to control where and how to import the private key. // Token: 0x060017C2 RID: 6082 RVA: 0x0004FCEC File Offset: 0x0004DEEC [global::System.MonoTODO("missing KeyStorageFlags support")] public override void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags) { base.Import(rawData, password, keyStorageFlags); if (password == null) { try { this._cert = new X509Certificate(rawData); } catch (Exception ex) { try { this.ImportPkcs12(rawData, null); } catch { string text = global::Locale.GetText("Unable to decode certificate."); throw new CryptographicException(text, ex); } } } else { try { this.ImportPkcs12(rawData, password); } catch { this._cert = 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. // Token: 0x060017C3 RID: 6083 RVA: 0x0004FDB8 File Offset: 0x0004DFB8 [global::System.MonoTODO("SecureString is incomplete")] public override void Import(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags) { this.Import(rawData, null, keyStorageFlags); } /// Populates an object with information from a certificate file. /// The name of a certificate. // Token: 0x060017C4 RID: 6084 RVA: 0x0004FDC4 File Offset: 0x0004DFC4 public override void Import(string fileName) { byte[] array = X509Certificate2.Load(fileName); this.Import(array, null, X509KeyStorageFlags.DefaultKeySet); } /// Populates an object with information from a certificate file, a password, and a value. /// The name of a certificate file. /// The password required to access the X.509 certificate data. /// One of the values used to control where and how to import the private key. // Token: 0x060017C5 RID: 6085 RVA: 0x0004FDE4 File Offset: 0x0004DFE4 [global::System.MonoTODO("missing KeyStorageFlags support")] public override void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags) { byte[] array = X509Certificate2.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. // Token: 0x060017C6 RID: 6086 RVA: 0x0004FE04 File Offset: 0x0004E004 [global::System.MonoTODO("SecureString is incomplete")] public override void Import(string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags) { byte[] array = X509Certificate2.Load(fileName); this.Import(array, null, keyStorageFlags); } // Token: 0x060017C7 RID: 6087 RVA: 0x0004FE24 File Offset: 0x0004E024 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; } /// Resets the state of an object. // Token: 0x060017C8 RID: 6088 RVA: 0x0004FE88 File Offset: 0x0004E088 public override void Reset() { this._cert = null; this._archived = false; this._extensions = null; this._name = string.Empty; this._serial = null; this._publicKey = null; this.issuer_name = null; this.subject_name = null; this.signature_algorithm = null; base.Reset(); } /// Displays an X.509 certificate in text format. /// The certificate information. // Token: 0x060017C9 RID: 6089 RVA: 0x0004FEE0 File Offset: 0x0004E0E0 public override string ToString() { if (this._cert == null) { return "System.Security.Cryptography.X509Certificates.X509Certificate2"; } return base.ToString(true); } /// Displays an X.509 certificate in text format. /// The certificate information. /// true to display the public key, private key, extensions, and so forth; false to display information that is similar to the class, including thumbprint, serial number, subject and issuer names, and so on. // Token: 0x060017CA RID: 6090 RVA: 0x0004FEFC File Offset: 0x0004E0FC public override string ToString(bool verbose) { if (this._cert == null) { return "System.Security.Cryptography.X509Certificates.X509Certificate2"; } if (!verbose) { return base.ToString(true); } string newLine = Environment.NewLine; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("[Version]{0} V{1}{0}{0}", newLine, this.Version); stringBuilder.AppendFormat("[Subject]{0} {1}{0}{0}", newLine, base.Subject); stringBuilder.AppendFormat("[Issuer]{0} {1}{0}{0}", newLine, base.Issuer); stringBuilder.AppendFormat("[Serial Number]{0} {1}{0}{0}", newLine, this.SerialNumber); stringBuilder.AppendFormat("[Not Before]{0} {1}{0}{0}", newLine, this.NotBefore); stringBuilder.AppendFormat("[Not After]{0} {1}{0}{0}", newLine, this.NotAfter); stringBuilder.AppendFormat("[Thumbprint]{0} {1}{0}{0}", newLine, this.Thumbprint); stringBuilder.AppendFormat("[Signature Algorithm]{0} {1}({2}){0}{0}", newLine, this.SignatureAlgorithm.FriendlyName, this.SignatureAlgorithm.Value); AsymmetricAlgorithm key = this.PublicKey.Key; stringBuilder.AppendFormat("[Public Key]{0} Algorithm: ", newLine); if (key is RSA) { stringBuilder.Append("RSA"); } else if (key is DSA) { stringBuilder.Append("DSA"); } else { stringBuilder.Append(key.ToString()); } stringBuilder.AppendFormat("{0} Length: {1}{0} Key Blob: ", newLine, key.KeySize); X509Certificate2.AppendBuffer(stringBuilder, this.PublicKey.EncodedKeyValue.RawData); stringBuilder.AppendFormat("{0} Parameters: ", newLine); X509Certificate2.AppendBuffer(stringBuilder, this.PublicKey.EncodedParameters.RawData); stringBuilder.Append(newLine); return stringBuilder.ToString(); } // Token: 0x060017CB RID: 6091 RVA: 0x000500A8 File Offset: 0x0004E2A8 private static void AppendBuffer(StringBuilder sb, byte[] buffer) { if (buffer == null) { return; } for (int i = 0; i < buffer.Length; i++) { sb.Append(buffer[i].ToString("x2")); if (i < buffer.Length - 1) { sb.Append(" "); } } } /// Performs a X.509 chain validation using basic validation policy. /// true if the validation succeeds; false if the validation fails. /// The certificate is unreadable. // Token: 0x060017CC RID: 6092 RVA: 0x00050100 File Offset: 0x0004E300 [global::System.MonoTODO("by default this depends on the incomplete X509Chain")] public bool Verify() { if (this._cert == null) { throw new CryptographicException(X509Certificate2.empty_error); } X509Chain x509Chain = (X509Chain)CryptoConfig.CreateFromName("X509Chain"); return x509Chain.Build(this); } /// Indicates the type of certificate contained in a byte array. /// An object. /// A byte array containing data from an X.509 certificate. /// /// has a zero length or is null. // Token: 0x060017CD RID: 6093 RVA: 0x00050144 File Offset: 0x0004E344 [global::System.MonoTODO("Detection limited to Cert, Pfx, Pkcs12, Pkcs7 and Unknown")] public static X509ContentType GetCertContentType(byte[] rawData) { if (rawData == null || rawData.Length == 0) { throw new ArgumentException("rawData"); } X509ContentType x509ContentType = X509ContentType.Unknown; try { ASN1 asn = new ASN1(rawData); if (asn.Tag != 48) { string text = global::Locale.GetText("Unable to decode certificate."); throw new CryptographicException(text); } if (asn.Count == 0) { return x509ContentType; } if (asn.Count == 3) { byte tag = asn[0].Tag; if (tag != 2) { if (tag == 48) { if (asn[1].Tag == 48 && asn[2].Tag == 3) { x509ContentType = X509ContentType.Cert; } } } else if (asn[1].Tag == 48 && asn[2].Tag == 48) { x509ContentType = X509ContentType.Pfx; } } if (asn[0].Tag == 6 && asn[0].CompareValue(X509Certificate2.signedData)) { x509ContentType = X509ContentType.Pkcs7; } } catch (Exception ex) { string text2 = global::Locale.GetText("Unable to decode certificate."); throw new CryptographicException(text2, ex); } return x509ContentType; } /// Indicates the type of certificate contained in a file. /// An object. /// The name of a certificate file. /// /// is null. // Token: 0x060017CE RID: 6094 RVA: 0x00050298 File Offset: 0x0004E498 [global::System.MonoTODO("Detection limited to Cert, Pfx, Pkcs12 and Unknown")] public static X509ContentType GetCertContentType(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } if (fileName.Length == 0) { throw new ArgumentException("fileName"); } byte[] array = X509Certificate2.Load(fileName); return X509Certificate2.GetCertContentType(array); } // Token: 0x17000786 RID: 1926 // (get) Token: 0x060017CF RID: 6095 RVA: 0x000502DC File Offset: 0x0004E4DC internal X509Certificate MonoCertificate { get { return this._cert; } } // Token: 0x040012F8 RID: 4856 private bool _archived; // Token: 0x040012F9 RID: 4857 private X509ExtensionCollection _extensions; // Token: 0x040012FA RID: 4858 private string _name = string.Empty; // Token: 0x040012FB RID: 4859 private string _serial; // Token: 0x040012FC RID: 4860 private PublicKey _publicKey; // Token: 0x040012FD RID: 4861 private X500DistinguishedName issuer_name; // Token: 0x040012FE RID: 4862 private X500DistinguishedName subject_name; // Token: 0x040012FF RID: 4863 private Oid signature_algorithm; // Token: 0x04001300 RID: 4864 private X509Certificate _cert; // Token: 0x04001301 RID: 4865 private static string empty_error = global::Locale.GetText("Certificate instance is empty."); // Token: 0x04001302 RID: 4866 private static byte[] commonName = new byte[] { 85, 4, 3 }; // Token: 0x04001303 RID: 4867 private static byte[] email = new byte[] { 42, 134, 72, 134, 247, 13, 1, 9, 1 }; // Token: 0x04001304 RID: 4868 private static byte[] signedData = new byte[] { 42, 134, 72, 134, 247, 13, 1, 7, 2 }; } }