Author Topic: ASN.1 How to (newbie)  (Read 2919 times)


  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
ASN.1 How to (newbie)
« on: January 16, 2018, 06:34:28 AM »
I'm doing some testing on the trial version of Chilkat.
I would like, if possible, a help to decode an ASN.1 item from an X509 certificate.
I would need to access the item with the OID: Within this item I have some other subitems but they are encoded.
At that point I only have the X509 certificate. How do I access these OIDs in the certificate?
I tried to use the Chilkat.Asn library. But I confess I'm kind of lost in how I load data into it. I tried to export the certificate to xml and then load by the LoadAsnXml method but without success. The example you have on the site did not help me much.

Here is an excerpt from my code:

Code: [Select]
                Chilkat.Cert cert = certStore.GetCertificate(i);

                string certXml = cert.ExportCertXml();
                if (certXml != null && certXml.Contains(""))
                    System.Xml.XmlDocument xml = new System.Xml.XmlDocument();

                    System.Xml.XmlNode node = xml.SelectSingleNode("/sequence/sequence/contextSpecific/sequence/sequence/oid");
                    if (node != null && node.InnerText == "")
                        string b64 = xml.SelectSingleNode("/sequence/sequence/contextSpecific/sequence/sequence/octets").InnerText;
                        string val = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(b64)); // almost there ... but don't

                        Chilkat.Asn obj = new Chilkat.Asn();
                        obj.LoadEncoded(b64, "base64");

                        string vv = obj.GetSubItem(0).ContentStr; // return ""

Thank you... sorry for my english.