<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />

DerT61String

public class DerT61String : DerStringBase
using Org.BouncyCastle.Utilities; using System; using System.IO; namespace Org.BouncyCastle.Asn1 { public class DerT61String : DerStringBase { internal class Meta : Asn1UniversalType { internal static readonly Asn1UniversalType Instance = new Meta(); private Meta() : base(typeof(DerT61String), 20) { } internal override Asn1Object FromImplicitPrimitive(DerOctetString octetString) { return CreatePrimitive(octetString.GetOctets()); } } private readonly byte[] m_contents; public static DerT61String GetInstance(object obj) { if (obj == null) return null; DerT61String derT61String = obj as DerT61String; if (derT61String != null) return derT61String; IAsn1Convertible asn1Convertible = obj as IAsn1Convertible; if (asn1Convertible != null) { DerT61String derT61String2 = asn1Convertible.ToAsn1Object() as DerT61String; if (derT61String2 != null) return derT61String2; } else { byte[] array = obj as byte[]; if (array != null) try { return (DerT61String)Meta.Instance.FromByteArray(array); } catch (IOException ex) { throw new ArgumentException("failed to construct T61 string from byte[]: " + ex.Message); } } throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj)); } public static DerT61String GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit) { return (DerT61String)Meta.Instance.GetContextInstance(taggedObject, declaredExplicit); } public DerT61String(string str) { if (str == null) throw new ArgumentNullException("str"); m_contents = Strings.ToByteArray(str); } public DerT61String(byte[] contents) : this(contents, true) { } internal DerT61String(byte[] contents, bool clone) { if (contents == null) throw new ArgumentNullException("contents"); m_contents = (clone ? Arrays.Clone(contents) : contents); } public override string GetString() { return Strings.FromByteArray(m_contents); } internal override IAsn1Encoding GetEncoding(int encoding) { return new PrimitiveEncoding(0, 20, m_contents); } internal override IAsn1Encoding GetEncodingImplicit(int encoding, int tagClass, int tagNo) { return new PrimitiveEncoding(tagClass, tagNo, m_contents); } internal sealed override DerEncoding GetEncodingDer() { return new PrimitiveDerEncoding(0, 20, m_contents); } internal sealed override DerEncoding GetEncodingDerImplicit(int tagClass, int tagNo) { return new PrimitiveDerEncoding(tagClass, tagNo, m_contents); } public byte[] GetOctets() { return Arrays.Clone(m_contents); } protected override bool Asn1Equals(Asn1Object asn1Object) { DerT61String derT61String = asn1Object as DerT61String; if (derT61String != null) return Arrays.AreEqual(m_contents, derT61String.m_contents); return false; } protected override int Asn1GetHashCode() { return Arrays.GetHashCode(m_contents); } internal static DerT61String CreatePrimitive(byte[] contents) { return new DerT61String(contents, false); } } }