Dumps details of ASN.1 formatted data to a text file
Public Declare Function ASN1_TextDump Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strFileOrPEMString As String, ByVal nOptions As Long) As Long
nRet = ASN1_TextDump(strFileOut, strFileOrPEMString, nOptions)
long __stdcall ASN1_TextDump(const char *szFileOut, const char *szFileOrPEMString, long nOptions);
If successful, the return value is zero; otherwise it returns a nonzero error code.
static int dipki::Asn1::TextDump (const std::string &outputFile, const std::string &asn1File, Opts opts=Opts::None)
static Asn1.text_dump(outputfile, asn1file, opts=0)
The input may be a binary file in BER/DER format or a text file in PEM or base64-encoded format, or may be passed as a base64 string or as a PEM string. Only data with an outer SEQUENCE is accepted, which is the rule for all common PKI-related ASN.1 files.
The output is a text file showing the structure of the ASN.1 formatted data.
All the bytes in the input are printed in hexadecimal form laid out to show the nested structure of the ASN.1 formatted data
together with comments beginning with "--" that give further details about the elements.
The length of each object is shown in bytes, for example
30 81 e0 --SEQUENCE/224 bytes
shows the tag (30) and length bytes (81 e0) which begin a SEQUENCE of length 224 bytes, equal to hexadecimal E0 bytes.
Use the PKI_ASN1_NOCOMMENTS option to hide the comments: the resulting hexadecimal output without comments should decode back
directly to the original binary file.
Dim nRet As Long Dim strInputFile As String Dim strOutFile As String strInputFile = "smallca.cer" strOutFile = "dumpasn1-smallca.cer.txt" Debug.Print "File: " & strInputFile nRet = ASN1_TextDump(strOutFile, strInputFile, 0) Debug.Print "ASN1_TextDump returns " & nRet ShowTextFile strOutFile ' Pass input as a string strInputFile = "MAQwAgUA" strOutFile = "dumpasn1.txt" Debug.Print "Input: " & strInputFile nRet = ASN1_TextDump(strOutFile, strInputFile, 0) Debug.Print "ASN1_TextDump returns " & nRet ShowTextFile strOutFile ' Again with no comments nRet = ASN1_TextDump(strOutFile, strInputFile, PKI_ASN1_NOCOMMENTS) Debug.Print "ASN1_TextDump returns " & nRet ShowTextFile strOutFile
File: smallca.cer
ASN1_TextDump returns 0
30 81 e0 --SEQUENCE/224 bytes
30 81 9a --SEQUENCE/154 bytes
02 01 --INTEGER/1 bytes
01
30 0d --SEQUENCE/13 bytes
06 09 --OBJECTIDENTIFIER/9 bytes
2a 86 48 86 f7 0d 01 01 05
--sha1WithRSAEncryption (1.2.840.113549.1.1.5)
05 00 --NULL/0 bytes
30 0c --SEQUENCE/12 bytes
31 0a --SET/10 bytes
30 08 --SEQUENCE/8 bytes
06 03 --OBJECTIDENTIFIER/3 bytes
55 04 03
--commonName (2.5.4.3)
13 01 --PRINTABLESTRING/1 bytes
41
--'A'
30 1e --SEQUENCE/30 bytes
17 0d --UTCTIME/13 bytes
39 39 30 39 31 39 30 31 30 38 34 37 5a
--'990919010847Z'
17 0d --UTCTIME/13 bytes
33 39 31 32 33 31 32 33 35 39 35 39 5a
--'391231235959Z'
30 0c --SEQUENCE/12 bytes
31 0a --SET/10 bytes
30 08 --SEQUENCE/8 bytes
06 03 --OBJECTIDENTIFIER/3 bytes
55 04 03
--commonName (2.5.4.3)
13 01 --PRINTABLESTRING/1 bytes
41
--'A'
30 4a --SEQUENCE/74 bytes
30 0d --SEQUENCE/13 bytes
06 09 --OBJECTIDENTIFIER/9 bytes
2a 86 48 86 f7 0d 01 01 01
--rsaEncryption (1.2.840.113549.1.1.1)
05 00 --NULL/0 bytes
03 39 --BITSTRING/57 bytes
00 --0 unused bits
--encapsulates:
30 36 --SEQUENCE/54 bytes
02 31 --INTEGER/49 bytes
02 f9 09 6a 7d 83 55 c2 71 ae f1 6a cb 45 41 ba
b3 22 a2 83 b5 ad de 70 e3 37 19 a7 c9 bb ee 76
4b e2 fc b8 5c c7 9b e2 3f 27 1f 6f b7 b5 36 80
19
02 01 --INTEGER/1 bytes
03
30 0d --SEQUENCE/13 bytes
06 09 --OBJECTIDENTIFIER/9 bytes
2a 86 48 86 f7 0d 01 01 05
--sha1WithRSAEncryption (1.2.840.113549.1.1.5)
05 00 --NULL/0 bytes
03 32 --BITSTRING/50 bytes
00 --0 unused bits
01 9a 9b b2 ec b9 cd fd 66 c6 94 5b 2e d6 96 dc
32 87 68 da 5e 6f 2e 5d 5a 7f e6 09 2e 60 8f 8c
45 a5 18 7e 06 1c e9 81 aa ea d6 f2 e3 14 7d 25
91
--(227 bytes)
Input: MAQwAgUA
ASN1_TextDump returns 0
30 04 --SEQUENCE/4 bytes
30 02 --SEQUENCE/2 bytes
05 00 --NULL/0 bytes
--(6 bytes)
ASN1_TextDump returns 0
30 04
30 02
05 00
ASN1_TextDumpToString ASN1_Type