private void AddAsnNode(Asn1Object asn, TreeNodeEx parent) { var nodeAsText = asn.ToString(); if ((asn is Asn1OctetString || asn is Asn1BitString) && nodeAsText.Length > 40) { nodeAsText = nodeAsText.Substring(0, 40) + "..."; } var treeNode = new TreeNodeEx(nodeAsText); var imageIndex = GetImageIndex(asn); treeNode.SelectedImageIndex = imageIndex; treeNode.ImageIndex = imageIndex; var asnt = asn as Asn1StructuredObject; if (asnt != null) { foreach (var asn2 in asnt.Nodes) { AddAsnNode(asn2, treeNode); } } treeNode.Tag = asn; parent.Nodes.Add(treeNode); }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static void AsString( string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string tab = indent + Tab; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerTaggedObject) { string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(tab, verbose, o.GetObject(), buf); } } else if (obj is BerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is DerUnknownTag) { string hex = Hex.ToHexString(((DerUnknownTag)obj).GetData()); buf.Append(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + hex + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated en = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal ext = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string tab = indent + Tab; if (ext.DirectReference != null) { buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine); } if (ext.IndirectReference != null) { buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine); } if (ext.DataValueDescriptor != null) { AsString(tab, verbose, ext.DataValueDescriptor, buf); } buf.Append(tab + "Encoding: " + ext.Encoding + NewLine); AsString(tab, verbose, ext.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
/// <summary> /// Return an Asn1 representation of this add request. /// #return an Asn1 representation of this object. /// </summary> public override string ToString() { return(Asn1Object.ToString()); }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static void AsString( string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string tab = indent + Tab; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerTaggedObject) { string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(tab, verbose, o.GetObject(), buf); } } else if (obj is BerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(tab, verbose, o.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated en = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + en.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal ext = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string tab = indent + Tab; if (ext.DirectReference != null) { buf.Append(tab + "Direct Reference: " + ext.DirectReference.Id + NewLine); } if (ext.IndirectReference != null) { buf.Append(tab + "Indirect Reference: " + ext.IndirectReference.ToString() + NewLine); } if (ext.DataValueDescriptor != null) { AsString(tab, verbose, ext.DataValueDescriptor, buf); } buf.Append(tab + "Encoding: " + ext.Encoding + NewLine); AsString(tab, verbose, ext.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
/// <summary> Return an Asn1 representation of this modify request /// /// #return an Asn1 representation of this object /// </summary> public override System.String ToString() { return(Asn1Object.ToString()); }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static string AsString( string indent, bool verbose, Asn1Object obj) { if (obj is Asn1Sequence) { StringBuilder buf = new StringBuilder(indent); string tab = indent + Tab; if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return buf.ToString(); } else if (obj is DerTaggedObject) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.GetObject())); } return buf.ToString(); } else if (obj is BerSet) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return buf.ToString(); } else if (obj is DerSet) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return buf.ToString(); } else if (obj is DerObjectIdentifier) { return indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine; } else if (obj is DerBoolean) { return indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine; } else if (obj is DerInteger) { return indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine; } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; return indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine; } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; return indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine; } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; return indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine; } else if (obj is DerIA5String) { return indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine; } else if (obj is DerUtf8String) { return indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine; } else if (obj is DerPrintableString) { return indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine; } else if (obj is DerVisibleString) { return indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine; } else if (obj is DerBmpString) { return indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine; } else if (obj is DerT61String) { return indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine; } else if (obj is DerUtcTime) { return indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine; } else if (obj is DerGeneralizedTime) { return indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine; } else if (obj is DerUnknownTag) { byte[] hex = Hex.Encode(((DerUnknownTag)obj).GetData()); return indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + Encoding.ASCII.GetString(hex, 0, hex.Length) + NewLine; } else if (obj is BerApplicationSpecific) { return outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj); } else if (obj is DerApplicationSpecific) { return outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj); } else { return indent + obj.ToString() + NewLine; } }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string text = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable item in (Asn1Sequence)obj) { if (item == null || item is Asn1Null) { buf.Append(text); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text, verbose, item.ToAsn1Object(), buf); } } } else if (obj is DerTaggedObject) { string text2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject derTaggedObject = (DerTaggedObject)obj; buf.Append(derTaggedObject.TagNo.ToString()); buf.Append(']'); if (!derTaggedObject.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (derTaggedObject.IsEmpty()) { buf.Append(text2); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(text2, verbose, derTaggedObject.GetObject(), buf); } } else if (obj is BerSet) { string text3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable item2 in (Asn1Set)obj) { if (item2 == null) { buf.Append(text3); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text3, verbose, item2.ToAsn1Object(), buf); } } } else if (obj is DerSet) { string text4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable item3 in (Asn1Set)obj) { if (item3 == null) { buf.Append(text4); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(text4, verbose, item3.ToAsn1Object(), buf); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { buf.Append(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string text5 = verbose ? dumpBinaryDataAsString(indent, octets) : ""; buf.Append(indent + "BER Octet String[" + octets.Length + "] " + text5 + NewLine); } else if (obj is DerOctetString) { byte[] octets2 = ((Asn1OctetString)obj).GetOctets(); string text6 = verbose ? dumpBinaryDataAsString(indent, octets2) : ""; buf.Append(indent + "DER Octet String[" + octets2.Length + "] " + text6 + NewLine); } else if (obj is DerBitString) { DerBitString derBitString = (DerBitString)obj; byte[] bytes = derBitString.GetBytes(); string text7 = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(indent + "DER Bit String[" + bytes.Length + ", " + derBitString.PadBits + "] " + text7 + NewLine); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerGraphicString) { buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine); } else if (obj is DerVideotexString) { buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated derEnumerated = (DerEnumerated)obj; buf.Append(indent + "DER Enumerated(" + derEnumerated.Value + ")" + NewLine); } else if (obj is DerExternal) { DerExternal derExternal = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string text8 = indent + " "; if (derExternal.DirectReference != null) { buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + NewLine); } if (derExternal.IndirectReference != null) { buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + NewLine); } if (derExternal.DataValueDescriptor != null) { AsString(text8, verbose, derExternal.DataValueDescriptor, buf); } buf.Append(text8 + "Encoding: " + derExternal.Encoding + NewLine); AsString(text8, verbose, derExternal.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } }
public static List <CertSimples> ListaCertificado(X509Certificate2Collection Certificados) { List <CertSimples> oLista = new List <CertSimples>(); for (int i = 0; i < Certificados.Count; i++) { X509Certificate2 oCertificado = Certificados[i]; CertSimples oCert = new CertSimples(); oCert.SerialNumber = oCertificado.SerialNumber; oCert.Subject = oCertificado.Subject; try { string[] DadosSubject = oCertificado.Subject.Split(','); if (DadosSubject[0].IndexOf(":") > -1) { oCert.Nome = DadosSubject[0].Substring(3, DadosSubject[0].IndexOf(":") - 3); } else { oCert.Nome = DadosSubject[0].Substring(3); } } catch (Exception ex) { oCert.Nome = oCert.Subject; } foreach (var obj in oCertificado.Extensions) { if (obj.Oid.Value == "2.5.29.17") //otherName { byte[] Dados = obj.RawData; Stream sm = new MemoryStream(Dados); // StreamReader oSr = new StreamReader(sm); //string teste = System.Text.Encoding.ASCII.GetString(Dados); DerSequence otherName = (DerSequence)Asn1Object.FromStream(sm); var objCollection = otherName.GetEnumerator(); while (objCollection.MoveNext()) { Org.BouncyCastle.Asn1.DerTaggedObject iSub = (Org.BouncyCastle.Asn1.DerTaggedObject)objCollection.Current; Asn1Object derObject = iSub.GetObject(); if (derObject.GetType().Name.Contains("DerSequence")) { var objSubCollection = ((DerSequence)derObject).GetEnumerator(); byte count = 0; string strOID = ""; DerOctetString strOctet;// = (DerOctetString)derObject; string strTexto = ""; while (objSubCollection.MoveNext()) { var Conteudo = objSubCollection.Current; if (count == 0) { strOID = Conteudo.ToString(); } else { Org.BouncyCastle.Asn1.DerTaggedObject subCampos = (Org.BouncyCastle.Asn1.DerTaggedObject)Conteudo; Asn1Object derSub = subCampos.GetObject(); try { if (derSub.GetType().Name.Contains("DerOctetString")) { strOctet = (DerOctetString)derSub; byte[] Texto = strOctet.GetOctets(); strTexto = System.Text.Encoding.ASCII.GetString(Texto); } else { DerPrintableString strPtrString = (DerPrintableString)derSub; strTexto = strPtrString.GetString(); } } catch (Exception ex) { strTexto = derSub.ToString(); } } count++; } if (strOID == "2.16.76.1.3.1") //PESSOA FÍSICA { //i· OID = 2.16.76.1.3.1 e conteúdo = nas primeiras 8(oito) posições, a data de nascimento do titular, no formato ddmmaaaa; nas 11(onze) posições subseqüentes, o Cadastro de Pessoa Física(CPF) do titular; nas 11(onze) posições subseqüentes, o Número de Identificação Social – NIS(PIS, PASEP ou CI); nas 15(quinze) posições subseqüentes, o número do Registro Geral(RG) do titular; nas 10(dez) posições subseqüentes, as siglas do órgão expedidor do RG e respectiva unidade da federação; try { oCert.DataNascimento = strTexto.Substring(0, 8); oCert.CPF = strTexto.Substring(8, 11); oCert.NIS = strTexto.Substring(19, 11); oCert.RG = strTexto.Substring(30, 15); oCert.OrgaoExpedidor = strTexto.Substring(45); oCert.Tipo = "F"; } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.3.1:" + ex.Message, ex); } } else if (strOID == "2.16.76.1.3.6") //PESSOA FÍSICA { //ii· OID = 2.16.76.1.3.6 e conteúdo = nas 12 (doze) posições o número do Cadastro Específico do INSS (CEI) da pessoa física titular do certificado; } else if (strOID == "2.16.76.1.3.6") //PESSOA FÍSICA { try { //iii· OID = 2.16.76.1.3.5 e conteúdo nas primeiras 12(doze) posições, o número de inscrição do Título de Eleitor; nas 3(três) posições subseqüentes, a Zona Eleitoral; nas 4(quatro) posições seguintes, a Seção; nas 22(vinte e duas) posições subseqüentes, o município e a UF do Título de Eleitor. oCert.TituloEleitor = strTexto.Substring(0, 12); oCert.ZonaEleitoral = strTexto.Substring(12, 3); oCert.SecaoEleitoral = strTexto.Substring(15, 4); oCert.MunicipioEleitoral = strTexto.Substring(19, 22); } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.3.6:" + ex.Message, ex); } } else if (strOID == "2.16.76.1.4.2.1.1") { try { oCert.OAB = strTexto; } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.4.2.1.1:" + ex.Message, ex); } } else if (strOID == "2.16.76.1.3.4") //PESSOA JURÍDICA { try { oCert.Tipo = "J"; //i· OID = 2.16.76.1.3.4 e conteúdo = nas primeiras 8(oito) posições, a data de nascimento do responsável pelo certificado, no formato ddmmaaaa; nas 11(onze) posições subseqüentes, o Cadastro de Pessoa Física(CPF) do responsável; nas 11(onze) posições subseqüentes, o Número de Identificação Social – NIS(PIS, PASEP ou CI); nas 15(quinze) posições subseqüentes, o número do Registro Geral(RG) do responsável; nas 10(dez) posições subseqüentes, as siglas do órgão expedidor do RG e respectiva Unidade da Federação; oCert.DataNascimento = strTexto.Substring(0, 8); oCert.CPF = strTexto.Substring(8, 11); try { oCert.NIS = strTexto.Substring(19, 11); oCert.RG = strTexto.Substring(30, 15); oCert.OrgaoExpedidor = strTexto.Substring(45, 10); } catch (Exception ex) { } } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.3.4:" + strTexto + "." + ex.Message, ex); } } else if (strOID == "2.16.76.1.3.2") //PESSOA JURÍDICA { //ii· OID = 2.16.76.1.3.2 e conteúdo = nome do responsável pelo certificado; try { oCert.NomeResponsavel = strTexto; } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.3.2:" + ex.Message, ex); } } else if (strOID == "2.16.76.1.3.3") //PESSOA JURÍDICA { //iii· OID = 2.16.76.1.3.3 e conteúdo = nas 14(quatorze) posições o número do Cadastro Nacional de Pessoa Jurídica(CNPJ) da pessoa jurídica titular do certificado; try { oCert.CNPJ = strTexto; } catch (Exception ex) { throw new Exception("Erro na leitura da OID=2.16.76.1.3.3:" + ex.Message, ex); } } else if (strOID == "2.16.76.1.3.7") //PESSOA JURÍDICA { //iv. OID = 2.16.76.1.3.7 e conteúdo = nas 12 (doze) posições o número do Cadastro Específico do INSS (CEI) da pessoa jurídica titular do certificado. } count = 0; } else { //i. rfc822Name contendo o endereço e-mail do titular do certificado. if (derObject.GetType().Name == "DerOctetString") { DerOctetString strOctet = (DerOctetString)derObject; byte[] Texto = strOctet.GetOctets(); string strTexto = System.Text.Encoding.ASCII.GetString(Texto); oCert.Email = strTexto; } else { string texto = derObject.GetType().Name; } } } sm.Close(); } } oCert.Certificado = oCertificado; oLista.Add(oCert); } return(oLista); }
/// <inheritdoc /> public override string ToString() => Asn1Object.ToString();
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static string AsString( string indent, bool verbose, Asn1Object obj) { if (obj is Asn1Sequence) { StringBuilder buf = new StringBuilder(indent); string tab = indent + Tab; if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Sequence)obj)) { if (o == null || o is Asn1Null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return(buf.ToString()); } else if (obj is DerTaggedObject) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; buf.Append(((int)o.TagNo).ToString()); buf.Append(']'); if (!o.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (o.IsEmpty()) { buf.Append(tab); buf.Append("EMPTY"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.GetObject())); } return(buf.ToString()); } else if (obj is BerSet) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return(buf.ToString()); } else if (obj is DerSet) { StringBuilder buf = new StringBuilder(); string tab = indent + Tab; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); foreach (Asn1Encodable o in ((Asn1Set)obj)) { if (o == null) { buf.Append(tab); buf.Append("NULL"); buf.Append(NewLine); } else { buf.Append(AsString(tab, verbose, o.ToAsn1Object())); } } return(buf.ToString()); } else if (obj is DerObjectIdentifier) { return(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { return(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + NewLine); } else if (obj is DerInteger) { return(indent + "Integer(" + ((DerInteger)obj).Value + ")" + NewLine); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; return(indent + "BER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string extra = verbose ? dumpBinaryDataAsString(indent, octets) : ""; return(indent + "DER Octet String" + "[" + octets.Length + "] " + extra + NewLine); } else if (obj is DerBitString) { DerBitString bt = (DerBitString)obj; byte[] bytes = bt.GetBytes(); string extra = verbose ? dumpBinaryDataAsString(indent, bytes) : ""; return(indent + "DER Bit String" + "[" + bytes.Length + ", " + bt.PadBits + "] " + extra + NewLine); } else if (obj is DerIA5String) { return(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { return(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { return(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { return(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { return(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { return(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { return(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { return(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is DerUnknownTag) { byte[] hex = Hex.Encode(((DerUnknownTag)obj).GetData()); return(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + Encoding.ASCII.GetString(hex, 0, hex.Length) + NewLine); } else if (obj is BerApplicationSpecific) { return(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { return(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else { return(indent + obj.ToString() + NewLine); } }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static string AsString( string indent, Asn1Object obj) { if (obj is Asn1Sequence) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); if (obj is DerSequence) { Buffer.Append("DER Sequence"); } else if (obj is BerSequence) { Buffer.Append("BER Sequence"); } else { Buffer.Append("Sequence"); } Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); foreach (object o in ((Asn1Sequence)obj)) { if (o == null || o.Equals(DerNull.Instance)) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return Buffer.ToString(); } else if (obj is DerTaggedObject) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); if (obj is BerTaggedObject) { Buffer.Append("BER Tagged ["); } else { Buffer.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; Buffer.Append(((int)o.TagNo).ToString()); Buffer.Append(']'); if (!o.IsExplicit()) { Buffer.Append(" IMPLICIT "); } Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); if (o.IsEmpty()) { Buffer.Append(tab); Buffer.Append("EMPTY"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); } else { Buffer.Append(AsString(tab, o.GetObject())); } return Buffer.ToString(); } else if (obj is BerSet) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); Buffer.Append("BER Set"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); foreach (object o in ((Asn1Set)obj)) { if (o == null) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return Buffer.ToString(); } else if (obj is DerSet) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); Buffer.Append("DER Set"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); foreach (object o in ((Asn1Set)obj)) { if (o == null) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append( // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return Buffer.ToString(); } else if (obj is DerObjectIdentifier) { return indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerBoolean) { return indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerInteger) { return indent + "Integer(" + ((DerInteger)obj).Value + ")" + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerOctetString) { return indent + obj.ToString() + "[" + ((Asn1OctetString)obj).GetOctets().Length + "] " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerIA5String) { return indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerPrintableString) { return indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerVisibleString) { return indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerBmpString) { return indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerT61String) { return indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerUtcTime) { return indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else if (obj is DerUnknownTag) { // MASC 20070308. CF compatibility patch byte[] hex = Hex.Encode(((DerUnknownTag)obj).GetData()); return indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + Encoding.ASCII.GetString(hex,0,hex.Length) + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } else { return indent + obj.ToString() + // MASC 20070308. CF compatibility patch #if !NETCF Environment.NewLine #else EnvironmentEx.NewLine #endif ; } }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { if (obj is Asn1Sequence) { string text = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator()) { while (enumerator.MoveNext()) { Asn1Encodable asn1Encodable = (Asn1Encodable)enumerator.Current; if (asn1Encodable == null || asn1Encodable is Asn1Null) { buf.Append(text); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text, verbose, asn1Encodable.ToAsn1Object(), buf); } } return; } } if (obj is DerTaggedObject) { string text2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject derTaggedObject = (DerTaggedObject)obj; buf.Append(derTaggedObject.TagNo.ToString()); buf.Append(']'); if (!derTaggedObject.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(Asn1Dump.NewLine); if (derTaggedObject.IsEmpty()) { buf.Append(text2); buf.Append("EMPTY"); buf.Append(Asn1Dump.NewLine); return; } Asn1Dump.AsString(text2, verbose, derTaggedObject.GetObject(), buf); return; } else { if (obj is BerSet) { string text3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator()) { while (enumerator2.MoveNext()) { Asn1Encodable asn1Encodable2 = (Asn1Encodable)enumerator2.Current; if (asn1Encodable2 == null) { buf.Append(text3); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text3, verbose, asn1Encodable2.ToAsn1Object(), buf); } } return; } } if (obj is DerSet) { string text4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(Asn1Dump.NewLine); using (IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator()) { while (enumerator3.MoveNext()) { Asn1Encodable asn1Encodable3 = (Asn1Encodable)enumerator3.Current; if (asn1Encodable3 == null) { buf.Append(text4); buf.Append("NULL"); buf.Append(Asn1Dump.NewLine); } else { Asn1Dump.AsString(text4, verbose, asn1Encodable3.ToAsn1Object(), buf); } } return; } } if (obj is DerObjectIdentifier) { buf.Append(string.Concat(new string[] { indent, "ObjectIdentifier(", ((DerObjectIdentifier)obj).Id, ")", Asn1Dump.NewLine })); return; } if (obj is DerBoolean) { buf.Append(string.Concat(new object[] { indent, "Boolean(", ((DerBoolean)obj).IsTrue, ")", Asn1Dump.NewLine })); return; } if (obj is DerInteger) { buf.Append(string.Concat(new object[] { indent, "Integer(", ((DerInteger)obj).Value, ")", Asn1Dump.NewLine })); return; } if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string text5 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets) : ""; buf.Append(string.Concat(new object[] { indent, "BER Octet String[", octets.Length, "] ", text5, Asn1Dump.NewLine })); return; } if (obj is DerOctetString) { byte[] octets2 = ((Asn1OctetString)obj).GetOctets(); string text6 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, octets2) : ""; buf.Append(string.Concat(new object[] { indent, "DER Octet String[", octets2.Length, "] ", text6, Asn1Dump.NewLine })); return; } if (obj is DerBitString) { DerBitString derBitString = (DerBitString)obj; byte[] bytes = derBitString.GetBytes(); string text7 = verbose ? Asn1Dump.dumpBinaryDataAsString(indent, bytes) : ""; buf.Append(string.Concat(new object[] { indent, "DER Bit String[", bytes.Length, ", ", derBitString.PadBits, "] ", text7, Asn1Dump.NewLine })); return; } if (obj is DerIA5String) { buf.Append(string.Concat(new string[] { indent, "IA5String(", ((DerIA5String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerUtf8String) { buf.Append(string.Concat(new string[] { indent, "UTF8String(", ((DerUtf8String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerPrintableString) { buf.Append(string.Concat(new string[] { indent, "PrintableString(", ((DerPrintableString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerVisibleString) { buf.Append(string.Concat(new string[] { indent, "VisibleString(", ((DerVisibleString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerBmpString) { buf.Append(string.Concat(new string[] { indent, "BMPString(", ((DerBmpString)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerT61String) { buf.Append(string.Concat(new string[] { indent, "T61String(", ((DerT61String)obj).GetString(), ") ", Asn1Dump.NewLine })); return; } if (obj is DerUtcTime) { buf.Append(string.Concat(new string[] { indent, "UTCTime(", ((DerUtcTime)obj).TimeString, ") ", Asn1Dump.NewLine })); return; } if (obj is DerGeneralizedTime) { buf.Append(string.Concat(new string[] { indent, "GeneralizedTime(", ((DerGeneralizedTime)obj).GetTime(), ") ", Asn1Dump.NewLine })); return; } if (obj is BerApplicationSpecific) { buf.Append(Asn1Dump.outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); return; } if (obj is DerApplicationSpecific) { buf.Append(Asn1Dump.outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); return; } if (obj is DerEnumerated) { DerEnumerated derEnumerated = (DerEnumerated)obj; buf.Append(string.Concat(new object[] { indent, "DER Enumerated(", derEnumerated.Value, ")", Asn1Dump.NewLine })); return; } if (obj is DerExternal) { DerExternal derExternal = (DerExternal)obj; buf.Append(indent + "External " + Asn1Dump.NewLine); string text8 = indent + " "; if (derExternal.DirectReference != null) { buf.Append(text8 + "Direct Reference: " + derExternal.DirectReference.Id + Asn1Dump.NewLine); } if (derExternal.IndirectReference != null) { buf.Append(text8 + "Indirect Reference: " + derExternal.IndirectReference.ToString() + Asn1Dump.NewLine); } if (derExternal.DataValueDescriptor != null) { Asn1Dump.AsString(text8, verbose, derExternal.DataValueDescriptor, buf); } buf.Append(string.Concat(new object[] { text8, "Encoding: ", derExternal.Encoding, Asn1Dump.NewLine })); Asn1Dump.AsString(text8, verbose, derExternal.ExternalContent, buf); return; } buf.Append(indent + obj.ToString() + Asn1Dump.NewLine); } }
/** * dump a Der object as a formatted string with indentation * * @param obj the Asn1Object to be dumped out. */ private static string AsString( string indent, Asn1Object obj) { if (obj is Asn1Sequence) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); if (obj is DerSequence) { Buffer.Append("DER Sequence"); } else if (obj is BerSequence) { Buffer.Append("BER Sequence"); } else { Buffer.Append("Sequence"); } Buffer.Append(Environment.NewLine); foreach (object o in ((Asn1Sequence)obj)) { if (o == null || o.Equals(DerNull.Instance)) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append(Environment.NewLine); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return(Buffer.ToString()); } else if (obj is DerTaggedObject) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); if (obj is BerTaggedObject) { Buffer.Append("BER Tagged ["); } else { Buffer.Append("Tagged ["); } DerTaggedObject o = (DerTaggedObject)obj; Buffer.Append(((int)o.TagNo).ToString()); Buffer.Append(']'); if (!o.IsExplicit()) { Buffer.Append(" IMPLICIT "); } Buffer.Append(Environment.NewLine); if (o.IsEmpty()) { Buffer.Append(tab); Buffer.Append("EMPTY"); Buffer.Append(Environment.NewLine); } else { Buffer.Append(AsString(tab, o.GetObject())); } return(Buffer.ToString()); } else if (obj is BerSet) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); Buffer.Append("BER Set"); Buffer.Append(Environment.NewLine); foreach (object o in ((Asn1Set)obj)) { if (o == null) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append(Environment.NewLine); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return(Buffer.ToString()); } else if (obj is DerSet) { StringBuilder Buffer = new StringBuilder(); string tab = indent + TAB; Buffer.Append(indent); Buffer.Append("DER Set"); Buffer.Append(Environment.NewLine); foreach (object o in ((Asn1Set)obj)) { if (o == null) { Buffer.Append(tab); Buffer.Append("Null"); Buffer.Append(Environment.NewLine); } else if (o is Asn1Object) { Buffer.Append(AsString(tab, (Asn1Object)o)); } else { Buffer.Append(AsString(tab, ((Asn1Encodable)o).ToAsn1Object())); } } return(Buffer.ToString()); } else if (obj is DerObjectIdentifier) { return(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + Environment.NewLine); } else if (obj is DerBoolean) { return(indent + "Boolean(" + ((DerBoolean)obj).IsTrue + ")" + Environment.NewLine); } else if (obj is DerInteger) { return(indent + "Integer(" + ((DerInteger)obj).Value + ")" + Environment.NewLine); } else if (obj is DerOctetString) { return(indent + obj.ToString() + "[" + ((Asn1OctetString)obj).GetOctets().Length + "] " + Environment.NewLine); } else if (obj is DerIA5String) { return(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + Environment.NewLine); } else if (obj is DerPrintableString) { return(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + Environment.NewLine); } else if (obj is DerVisibleString) { return(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + Environment.NewLine); } else if (obj is DerBmpString) { return(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + Environment.NewLine); } else if (obj is DerT61String) { return(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + Environment.NewLine); } else if (obj is DerUtcTime) { return(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + Environment.NewLine); } else if (obj is DerUnknownTag) { return(indent + "Unknown " + ((int)((DerUnknownTag)obj).Tag).ToString("X") + " " + Encoding.ASCII.GetString(Hex.Encode(((DerUnknownTag)obj).GetData())) + Environment.NewLine); } else { return(indent + obj.ToString() + Environment.NewLine); } }
private static void AsString(string indent, bool verbose, Asn1Object obj, StringBuilder buf) { switch (obj) { case (Asn1Sequence _): { string str = indent + " "; buf.Append(indent); if (obj is BerSequence) { buf.Append("BER Sequence"); } else if (obj is DerSequence) { buf.Append("DER Sequence"); } else { buf.Append("Sequence"); } buf.Append(NewLine); IEnumerator enumerator = ((Asn1Sequence)obj).GetEnumerator(); try { while (enumerator.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator.Current; if ((current == null) || (current is Asn1Null)) { buf.Append(str); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator is IDisposable disposable) { IDisposable disposable; disposable.Dispose(); } } break; } default: if (obj is DerTaggedObject) { string str2 = indent + " "; buf.Append(indent); if (obj is BerTaggedObject) { buf.Append("BER Tagged ["); } else { buf.Append("Tagged ["); } DerTaggedObject obj2 = (DerTaggedObject)obj; buf.Append(obj2.TagNo.ToString()); buf.Append(']'); if (!obj2.IsExplicit()) { buf.Append(" IMPLICIT "); } buf.Append(NewLine); if (obj2.IsEmpty()) { buf.Append(str2); buf.Append("EMPTY"); buf.Append(NewLine); } else { AsString(str2, verbose, obj2.GetObject(), buf); } } else { switch (obj) { case (BerSet _): { string str3 = indent + " "; buf.Append(indent); buf.Append("BER Set"); buf.Append(NewLine); IEnumerator enumerator2 = ((Asn1Set)obj).GetEnumerator(); try { while (enumerator2.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator2.Current; if (current == null) { buf.Append(str3); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str3, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator2 is IDisposable disposable2) { IDisposable disposable2; disposable2.Dispose(); } } break; } default: if (obj is DerSet) { string str4 = indent + " "; buf.Append(indent); buf.Append("DER Set"); buf.Append(NewLine); IEnumerator enumerator3 = ((Asn1Set)obj).GetEnumerator(); try { while (enumerator3.MoveNext()) { Asn1Encodable current = (Asn1Encodable)enumerator3.Current; if (current == null) { buf.Append(str4); buf.Append("NULL"); buf.Append(NewLine); } else { AsString(str4, verbose, current.ToAsn1Object(), buf); } } } finally { if (enumerator3 is IDisposable disposable3) { IDisposable disposable3; disposable3.Dispose(); } } } else if (obj is DerObjectIdentifier) { buf.Append(indent + "ObjectIdentifier(" + ((DerObjectIdentifier)obj).Id + ")" + NewLine); } else if (obj is DerBoolean) { buf.Append(string.Concat(new object[] { indent, "Boolean(", ((DerBoolean)obj).IsTrue, ")", NewLine })); } else if (obj is DerInteger) { buf.Append(string.Concat(new object[] { indent, "Integer(", ((DerInteger)obj).Value, ")", NewLine })); } else if (obj is BerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string str5 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets); buf.Append(string.Concat(new object[] { indent, "BER Octet String[", octets.Length, "] ", str5, NewLine })); } else if (obj is DerOctetString) { byte[] octets = ((Asn1OctetString)obj).GetOctets(); string str6 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, octets); buf.Append(string.Concat(new object[] { indent, "DER Octet String[", octets.Length, "] ", str6, NewLine })); } else if (obj is DerBitString) { DerBitString str7 = (DerBitString)obj; byte[] bytes = str7.GetBytes(); string str8 = !verbose ? string.Empty : dumpBinaryDataAsString(indent, bytes); buf.Append(string.Concat(new object[] { indent, "DER Bit String[", bytes.Length, ", ", str7.PadBits, "] ", str8, NewLine })); } else if (obj is DerIA5String) { buf.Append(indent + "IA5String(" + ((DerIA5String)obj).GetString() + ") " + NewLine); } else if (obj is DerUtf8String) { buf.Append(indent + "UTF8String(" + ((DerUtf8String)obj).GetString() + ") " + NewLine); } else if (obj is DerPrintableString) { buf.Append(indent + "PrintableString(" + ((DerPrintableString)obj).GetString() + ") " + NewLine); } else if (obj is DerVisibleString) { buf.Append(indent + "VisibleString(" + ((DerVisibleString)obj).GetString() + ") " + NewLine); } else if (obj is DerBmpString) { buf.Append(indent + "BMPString(" + ((DerBmpString)obj).GetString() + ") " + NewLine); } else if (obj is DerT61String) { buf.Append(indent + "T61String(" + ((DerT61String)obj).GetString() + ") " + NewLine); } else if (obj is DerGraphicString) { buf.Append(indent + "GraphicString(" + ((DerGraphicString)obj).GetString() + ") " + NewLine); } else if (obj is DerVideotexString) { buf.Append(indent + "VideotexString(" + ((DerVideotexString)obj).GetString() + ") " + NewLine); } else if (obj is DerUtcTime) { buf.Append(indent + "UTCTime(" + ((DerUtcTime)obj).TimeString + ") " + NewLine); } else if (obj is DerGeneralizedTime) { buf.Append(indent + "GeneralizedTime(" + ((DerGeneralizedTime)obj).GetTime() + ") " + NewLine); } else if (obj is BerApplicationSpecific) { buf.Append(outputApplicationSpecific("BER", indent, verbose, (BerApplicationSpecific)obj)); } else if (obj is DerApplicationSpecific) { buf.Append(outputApplicationSpecific("DER", indent, verbose, (DerApplicationSpecific)obj)); } else if (obj is DerEnumerated) { DerEnumerated enumerated = (DerEnumerated)obj; buf.Append(string.Concat(new object[] { indent, "DER Enumerated(", enumerated.Value, ")", NewLine })); } else if (obj is DerExternal) { DerExternal external = (DerExternal)obj; buf.Append(indent + "External " + NewLine); string str9 = indent + " "; if (external.DirectReference != null) { buf.Append(str9 + "Direct Reference: " + external.DirectReference.Id + NewLine); } if (external.IndirectReference != null) { buf.Append(str9 + "Indirect Reference: " + external.IndirectReference.ToString() + NewLine); } if (external.DataValueDescriptor != null) { AsString(str9, verbose, external.DataValueDescriptor, buf); } buf.Append(string.Concat(new object[] { str9, "Encoding: ", external.Encoding, NewLine })); AsString(str9, verbose, external.ExternalContent, buf); } else { buf.Append(indent + obj.ToString() + NewLine); } break; } } break; } }