1

I have an array of bytes that is der encoded, I need to decode these bytes into asn1 object using Powershell or by accessing a C# library from powershell. In python there is a module built to do this process called pyasn1.

I tried using the C# class ASNEncodedData but it doesn't provide a der decoder. I did accomplish the process successfully using the following in python.

Python Code to decode Der in hex form into asn1 object:

import from pyasn1.codec.der import decoder
asn1_object = decoder.decode(hexadecimal)

I expect to be able to decode the der encoded data into an asn1 object that looks like this:

{
  "type": "0x30",
  "lengthSize": 0,
  "length": 89,
  "children": [
    {
      "type": "0x30",
      "lengthSize": 0,
      "length": 19,
      "children": [
        {
          "type": "0x06",
          "lengthSize": 0,
          "length": 7,
          "value": "0x2a8648ce3d0201"
        },
        {
          "type": "0x06",
          "lengthSize": 0,
          "length": 8,
          "value": "0x2a8648ce3d030107"
        }
      ]
    },
    {
      "type": "0x03",
      "lengthSize": 0,
      "length": 66,
      "value": "0x04213d5258bc6c69c3e2139675ea3928a409fcffef39acc8e0c82a24ae78c37ede98fd89c0e00e74c997bb0a716ca9e0dca673dbb9b3fa72962255c9debcd218ca",
      "children": []
    }
  ]
}
Henry
  • 23
  • 2
  • There is no built-in support for ASN decoder in PowerShell or .NET, you have to use 3rd party libraries to decode ASN.1-encoded binary data. – Crypt32 Oct 28 '19 at 07:54
  • @Crypt32, thank you I this is what I need. But can you please direct me to the Function I need to use, since CMDLET names doesn't show anything related to der or asn1 objects. – Henry Oct 28 '19 at 08:00
  • As I said, PowerShell has no built-in ASN.1 decoder support. The best option is to find a 3rd party .NET library that provides ASN.1 decoder and use their APIs and some coding to construct desired JSON. – Crypt32 Oct 28 '19 at 08:36

0 Answers0