Files
Dec2017-Script-Dump/System/Security/Cryptography/AsnEncodedData.cs
T
2026-06-04 11:42:34 +02:00

387 lines
12 KiB
C#

using System;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Mono.Security;
using Mono.Security.Cryptography;
namespace System.Security.Cryptography
{
/// <summary>Represents Abstract Syntax Notation One (ASN.1)-encoded data.</summary>
// Token: 0x020002A4 RID: 676
public class AsnEncodedData
{
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class.</summary>
// Token: 0x060018A5 RID: 6309 RVA: 0x00054630 File Offset: 0x00052830
protected AsnEncodedData()
{
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class using a byte array.</summary>
/// <param name="oid">A string that represents <see cref="T:System.Security.Cryptography.Oid" /> information.</param>
/// <param name="rawData">A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.</param>
// Token: 0x060018A6 RID: 6310 RVA: 0x00054638 File Offset: 0x00052838
public AsnEncodedData(string oid, byte[] rawData)
{
this._oid = new Oid(oid);
this.RawData = rawData;
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class using an <see cref="T:System.Security.Cryptography.Oid" /> object and a byte array.</summary>
/// <param name="oid">An <see cref="T:System.Security.Cryptography.Oid" /> object.</param>
/// <param name="rawData">A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.</param>
// Token: 0x060018A7 RID: 6311 RVA: 0x00054654 File Offset: 0x00052854
public AsnEncodedData(Oid oid, byte[] rawData)
{
this.Oid = oid;
this.RawData = rawData;
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class using an instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class.</summary>
/// <param name="asnEncodedData">An instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="asnEncodedData" /> is null.</exception>
// Token: 0x060018A8 RID: 6312 RVA: 0x0005466C File Offset: 0x0005286C
public AsnEncodedData(AsnEncodedData asnEncodedData)
{
if (asnEncodedData == null)
{
throw new ArgumentNullException("asnEncodedData");
}
if (asnEncodedData._oid != null)
{
this.Oid = new Oid(asnEncodedData._oid);
}
this.RawData = asnEncodedData._raw;
}
/// <summary>Initializes a new instance of the <see cref="T:System.Security.Cryptography.AsnEncodedData" /> class using a byte array.</summary>
/// <param name="rawData">A byte array that contains Abstract Syntax Notation One (ASN.1)-encoded data.</param>
// Token: 0x060018A9 RID: 6313 RVA: 0x000546B8 File Offset: 0x000528B8
public AsnEncodedData(byte[] rawData)
{
this.RawData = rawData;
}
/// <summary>Gets or sets the <see cref="T:System.Security.Cryptography.Oid" /> value for an <see cref="T:System.Security.Cryptography.AsnEncodedData" /> object.</summary>
/// <returns>An <see cref="T:System.Security.Cryptography.Oid" /> object.</returns>
// Token: 0x170007BB RID: 1979
// (get) Token: 0x060018AA RID: 6314 RVA: 0x000546C8 File Offset: 0x000528C8
// (set) Token: 0x060018AB RID: 6315 RVA: 0x000546D0 File Offset: 0x000528D0
public Oid Oid
{
get
{
return this._oid;
}
set
{
if (value == null)
{
this._oid = null;
}
else
{
this._oid = new Oid(value);
}
}
}
/// <summary>Gets or sets the Abstract Syntax Notation One (ASN.1)-encoded data represented in a byte array.</summary>
/// <returns>A byte array that represents the Abstract Syntax Notation One (ASN.1)-encoded data.</returns>
/// <exception cref="T:System.ArgumentNullException">The value is null.</exception>
// Token: 0x170007BC RID: 1980
// (get) Token: 0x060018AC RID: 6316 RVA: 0x000546F0 File Offset: 0x000528F0
// (set) Token: 0x060018AD RID: 6317 RVA: 0x000546F8 File Offset: 0x000528F8
public byte[] RawData
{
get
{
return this._raw;
}
set
{
if (value == null)
{
throw new ArgumentNullException("RawData");
}
this._raw = (byte[])value.Clone();
}
}
/// <summary>Copies information from an <see cref="T:System.Security.Cryptography.AsnEncodedData" /> object.</summary>
/// <param name="asnEncodedData">The <see cref="T:System.Security.Cryptography.AsnEncodedData" /> object to base the new object on.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="asnEncodedData " />is null.</exception>
// Token: 0x060018AE RID: 6318 RVA: 0x00054728 File Offset: 0x00052928
public virtual void CopyFrom(AsnEncodedData asnEncodedData)
{
if (asnEncodedData == null)
{
throw new ArgumentNullException("asnEncodedData");
}
if (asnEncodedData._oid == null)
{
this.Oid = null;
}
else
{
this.Oid = new Oid(asnEncodedData._oid);
}
this.RawData = asnEncodedData._raw;
}
/// <summary>Returns a formatted version of the Abstract Syntax Notation One (ASN.1)-encoded data as a string.</summary>
/// <returns>A formatted string that represents the Abstract Syntax Notation One (ASN.1)-encoded data.</returns>
/// <param name="multiLine">true if the return string should contain carriage returns; otherwise, false.</param>
// Token: 0x060018AF RID: 6319 RVA: 0x0005477C File Offset: 0x0005297C
public virtual string Format(bool multiLine)
{
if (this._raw == null)
{
return string.Empty;
}
if (this._oid == null)
{
return this.Default(multiLine);
}
return this.ToString(multiLine);
}
// Token: 0x060018B0 RID: 6320 RVA: 0x000547AC File Offset: 0x000529AC
internal virtual string ToString(bool multiLine)
{
string value = this._oid.Value;
switch (value)
{
case "2.5.29.19":
return this.BasicConstraintsExtension(multiLine);
case "2.5.29.37":
return this.EnhancedKeyUsageExtension(multiLine);
case "2.5.29.15":
return this.KeyUsageExtension(multiLine);
case "2.5.29.14":
return this.SubjectKeyIdentifierExtension(multiLine);
case "2.5.29.17":
return this.SubjectAltName(multiLine);
case "2.16.840.1.113730.1.1":
return this.NetscapeCertType(multiLine);
}
return this.Default(multiLine);
}
// Token: 0x060018B1 RID: 6321 RVA: 0x00054898 File Offset: 0x00052A98
internal string Default(bool multiLine)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < this._raw.Length; i++)
{
stringBuilder.Append(this._raw[i].ToString("x2"));
if (i != this._raw.Length - 1)
{
stringBuilder.Append(" ");
}
}
return stringBuilder.ToString();
}
// Token: 0x060018B2 RID: 6322 RVA: 0x00054904 File Offset: 0x00052B04
internal string BasicConstraintsExtension(bool multiLine)
{
string text;
try
{
global::System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension x509BasicConstraintsExtension = new global::System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension(this, false);
text = x509BasicConstraintsExtension.ToString(multiLine);
}
catch
{
text = string.Empty;
}
return text;
}
// Token: 0x060018B3 RID: 6323 RVA: 0x0005495C File Offset: 0x00052B5C
internal string EnhancedKeyUsageExtension(bool multiLine)
{
string text;
try
{
global::System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension x509EnhancedKeyUsageExtension = new global::System.Security.Cryptography.X509Certificates.X509EnhancedKeyUsageExtension(this, false);
text = x509EnhancedKeyUsageExtension.ToString(multiLine);
}
catch
{
text = string.Empty;
}
return text;
}
// Token: 0x060018B4 RID: 6324 RVA: 0x000549B4 File Offset: 0x00052BB4
internal string KeyUsageExtension(bool multiLine)
{
string text;
try
{
global::System.Security.Cryptography.X509Certificates.X509KeyUsageExtension x509KeyUsageExtension = new global::System.Security.Cryptography.X509Certificates.X509KeyUsageExtension(this, false);
text = x509KeyUsageExtension.ToString(multiLine);
}
catch
{
text = string.Empty;
}
return text;
}
// Token: 0x060018B5 RID: 6325 RVA: 0x00054A0C File Offset: 0x00052C0C
internal string SubjectKeyIdentifierExtension(bool multiLine)
{
string text;
try
{
global::System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierExtension x509SubjectKeyIdentifierExtension = new global::System.Security.Cryptography.X509Certificates.X509SubjectKeyIdentifierExtension(this, false);
text = x509SubjectKeyIdentifierExtension.ToString(multiLine);
}
catch
{
text = string.Empty;
}
return text;
}
// Token: 0x060018B6 RID: 6326 RVA: 0x00054A64 File Offset: 0x00052C64
internal string SubjectAltName(bool multiLine)
{
if (this._raw.Length < 5)
{
return "Information Not Available";
}
string text3;
try
{
ASN1 asn = new ASN1(this._raw);
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < asn.Count; i++)
{
ASN1 asn2 = asn[i];
byte tag = asn2.Tag;
string text;
string text2;
if (tag != 129)
{
if (tag != 130)
{
text = string.Format("Unknown ({0})=", asn2.Tag);
text2 = CryptoConvert.ToHex(asn2.Value);
}
else
{
text = "DNS Name=";
text2 = Encoding.ASCII.GetString(asn2.Value);
}
}
else
{
text = "RFC822 Name=";
text2 = Encoding.ASCII.GetString(asn2.Value);
}
stringBuilder.Append(text);
stringBuilder.Append(text2);
if (multiLine)
{
stringBuilder.Append(Environment.NewLine);
}
else if (i < asn.Count - 1)
{
stringBuilder.Append(", ");
}
}
text3 = stringBuilder.ToString();
}
catch
{
text3 = string.Empty;
}
return text3;
}
// Token: 0x060018B7 RID: 6327 RVA: 0x00054BCC File Offset: 0x00052DCC
internal string NetscapeCertType(bool multiLine)
{
if (this._raw.Length < 4 || this._raw[0] != 3 || this._raw[1] != 2)
{
return "Information Not Available";
}
int num = this._raw[3] >> (int)this._raw[2] << (int)this._raw[2];
StringBuilder stringBuilder = new StringBuilder();
if ((num & 128) == 128)
{
stringBuilder.Append("SSL Client Authentication");
}
if ((num & 64) == 64)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("SSL Server Authentication");
}
if ((num & 32) == 32)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("SMIME");
}
if ((num & 16) == 16)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("Signature");
}
if ((num & 8) == 8)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("Unknown cert type");
}
if ((num & 4) == 4)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("SSL CA");
}
if ((num & 2) == 2)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("SMIME CA");
}
if ((num & 1) == 1)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(", ");
}
stringBuilder.Append("Signature CA");
}
stringBuilder.AppendFormat(" ({0})", num.ToString("x2"));
return stringBuilder.ToString();
}
// Token: 0x0400139F RID: 5023
internal Oid _oid;
// Token: 0x040013A0 RID: 5024
internal byte[] _raw;
}
}