---
product: Chilkat
product_version: 11.7.0
language: b4x
language_label: B4X
class: Asn
class_name: ChilkatAsn
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/b4x_AsnRef.html
---
# Chilkat Asn — B4X — v11.7.0

> Chilkat 11.7.0 · language=b4x · class=Asn (ChilkatAsn)
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/Asn.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/b4x/guide.md`.

## Purpose

**Load, inspect, build, edit, and encode ASN.1 structures in DER or XML form.**

`Chilkat.Asn` represents an ASN.1 item and its optional child items. It can load ASN.1 from binary DER, encoded DER strings, files, or `BinData`; expose tags, tag values, primitive content, boolean and integer values, and child counts; build constructed structures such as `SEQUENCE` and `SET`; append common primitive types such as booleans, integers, big integers, bit strings, octets, OIDs, strings, times, null values, and context-specific items; convert ASN.1 to XML; reload from that XML form; and write the final structure back to DER.

**Load DER data**

Load ASN.1 from binary DER bytes, encoded text such as Base64 or hex, files, or existing `BinData` objects.

**Inspect ASN.1 items**

Read the item tag, tag value, constructed/primitive state, sub-item count, string content, boolean value, or integer value.

**Build sequences and sets**

Append constructed `SEQUENCE` and `SET` items, then add child ASN.1 values beneath them.

**Append primitive values**

Add booleans, integers, big integers, bit strings, octet strings, OIDs, strings, times, null values, and encoded byte content.

**Context-specific tags**

Add context-specific primitive or constructed items when working with ASN.1 formats that use tagged application-specific structures.

**DER and XML conversion**

Convert ASN.1 to XML for inspection or editing, load ASN.1 back from XML, and output the result as binary or encoded DER.

**Common pattern:** Load existing DER with `LoadBinary`, `LoadEncoded`, `LoadBd`, or `LoadBinaryFile`, inspect the tree with `Tag`, `Constructed`, `NumSubItems`, and `GetSubItem`, then extract primitive content or convert to XML with `AsnToXml`. To create ASN.1, start with a constructed item, append child values, and write the final DER with `GetBinaryDer`, `GetEncodedDer`, `WriteBd`, or `WriteBinaryDer`.

## Object creation, unlocking and error handling

**Declare / Initialize / Dispose**

```visual-basic
Sub Process_Globals
    Private obj As ChilkatAsn
End Sub

' Call Initialize before first use -- typically in AppStart (B4J)
' or Activity_Create (B4A):
obj.Initialize                ' classes without events
obj.Initialize("evt")        ' classes with events: "evt" becomes the
                              ' prefix of event Subs such as evt_PercentDone
```

`Initialize / Initialize (EventName As String)`

Creates the underlying native Chilkat object. Classes that support events take an `EventName` argument: it becomes the prefix of the event Subs (`<EventName>_AbortCheck`, `<EventName>_PercentDone`, `<EventName>_ProgressInfo`); classes without events take no arguments. The native Chilkat library loads automatically on the first Initialize — from the APK on Android, or extracted from ChilkatB4J.jar on Windows/Linux/macOS.

`IsInitialized As Boolean`

`True` if `Initialize` has been called and the native object exists.

`Dispose`

Explicitly frees the underlying native object. Calling `Dispose` is optional — every ChilkatAsn is also freed automatically when garbage-collected — but is recommended for long-lived objects holding sockets, sessions, or large buffers. A disposed object can be re-Initialized.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in B4X.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `' read/write DebugLogFilePath As String` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastErrorHtml` | `' read-only LastErrorHtml As String` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `' read-only LastErrorText As String` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `' read-only LastErrorXml As String` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `' read/write LastMethodSuccess As Boolean` | read/write | Indicates the success or failure of the most recent method call: `True` means success, `False` means failure. |
| `VerboseLogging` | `' read/write VerboseLogging As Boolean` | read/write | If set to `True`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `' read-only Version As String` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `BoolValue` | property, read/write | `' read/write BoolValue As Boolean` |
| `Constructed` | property, read-only | `' read-only Constructed As Boolean` |
| `ContentStr` | property, read/write | `' read/write ContentStr As String` |
| `IntValue` | property, read/write | `' read/write IntValue As Int` |
| `NumSubItems` | property, read-only | `' read-only NumSubItems As Int` |
| `Tag` | property, read-only | `' read-only Tag As String` |
| `TagValue` | property, read-only | `' read-only TagValue As Int` |
| `AppendBigInt` | method | `AppendBigInt (encodedBytes As String, encoding As String) As Boolean` |
| `AppendBits` | method | `AppendBits (encodedBytes As String, encoding As String) As Boolean` |
| `AppendBool` | method | `AppendBool (value As Boolean) As Boolean` |
| `AppendContextConstructed` | method | `AppendContextConstructed (tag As Int) As Boolean` |
| `AppendContextPrimitive` | method | `AppendContextPrimitive (tag As Int, encodedBytes As String, encoding As String) As Boolean` |
| `AppendInt` | method | `AppendInt (value As Int) As Boolean` |
| `AppendNull` | method | `AppendNull As Boolean` |
| `AppendOctets` | method | `AppendOctets (encodedBytes As String, encoding As String) As Boolean` |
| `AppendOid` | method | `AppendOid (oid As String) As Boolean` |
| `AppendSequence` | method | `AppendSequence As Boolean` |
| `AppendSequence2` | method | `AppendSequence2 As Boolean` |
| `AppendSequenceR` | method | `AppendSequenceR As ChilkatAsn` |
| `AppendSet` | method | `AppendSet As Boolean` |
| `AppendSet2` | method | `AppendSet2 As Boolean` |
| `AppendSetR` | method | `AppendSetR As ChilkatAsn` |
| `AppendString` | method | `AppendString (strType As String, value As String) As Boolean` |
| `AppendTime` | method | `AppendTime (timeFormat As String, dateTimeStr As String) As Boolean` |
| `AsnToXml` | method | `AsnToXml As String` |
| `DeleteSubItem` | method | `DeleteSubItem (index As Int) As Boolean` |
| `GetEncodedContent` | method | `GetEncodedContent (encoding As String) As String` |
| `GetEncodedDer` | method | `GetEncodedDer (encoding As String) As String` |
| `GetLastSubItem` | method | `GetLastSubItem As ChilkatAsn` |
| `GetSubItem` | method | `GetSubItem (index As Int) As ChilkatAsn` |
| `LoadAsnXml` | method | `LoadAsnXml (xmlStr As String) As Boolean` |
| `LoadBd` | method | `LoadBd (bd As ChilkatBinData) As Boolean` |
| `LoadBinaryFile` | method | `LoadBinaryFile (path As String) As Boolean` |
| `LoadEncoded` | method | `LoadEncoded (asnContent As String, encoding As String) As Boolean` |
| `SetEncodedContent` | method | `SetEncodedContent (encodedBytes As String, encoding As String) As Boolean` |
| `WriteBd` | method | `WriteBd (bd As ChilkatBinData) As Boolean` |
| `WriteBinaryDer` | method | `WriteBinaryDer (path As String) As Boolean` |

## Properties

### Asn.BoolValue

`Chilkat 11.7.0 · b4x · Asn · BoolValue · property · read/write · since 9.5.0.49`

```visual-basic
' read/write

BoolValue As Boolean
```

The ASN.1 item's boolean value if it is a boolean item.

### Asn.Constructed

`Chilkat 11.7.0 · b4x · Asn · Constructed · property · read-only · since 9.5.0.49`

```visual-basic
' read-only

Constructed As Boolean
```

`True` if this ASN.1 item is a constructed item. Sequence and Set items are constructed and can contain sub-items. All other tags (boolean, integer, octets, utf8String, etc.) are primitive (non-constructed).

### Asn.ContentStr

`Chilkat 11.7.0 · b4x · Asn · ContentStr · property · read/write · since 9.5.0.49`

```visual-basic
' read/write

ContentStr As String
```

The ASN.1 item's content if it is an ASN.1 string type (such as Utf8String, BmpString, PrintableString, VisibleString, T61String, IA5String, NumericString, or UniversalString).

### Asn.IntValue

`Chilkat 11.7.0 · b4x · Asn · IntValue · property · read/write · since 9.5.0.49`

```visual-basic
' read/write

IntValue As Int
```

The ASN.1 item's integer value if it is a small integer item.

### Asn.NumSubItems

`Chilkat 11.7.0 · b4x · Asn · NumSubItems · property · read-only · since 9.5.0.49`

```visual-basic
' read-only

NumSubItems As Int
```

The number of sub-items contained within this ASN.1 item. Only constructed items, such as Sequence and Set will contain sub-iitems. Primitive items such as OIDs, octet strings, integers, etc. will never contain sub-items.

### Asn.Tag

`Chilkat 11.7.0 · b4x · Asn · Tag · property · read-only · since 9.5.0.49`

```visual-basic
' read-only

Tag As String
```

The ASN.1 item's tag as a descriptive string. Possible values are:

```
boolean
integer
bitString
octets
null
oid
utf8String
relativeOid
sequence
set
numericString
printableString
t61String
ia5String
utcTime
bmpString
```

### Asn.TagValue

`Chilkat 11.7.0 · b4x · Asn · TagValue · property · read-only · since 9.5.0.49`

```visual-basic
' read-only

TagValue As Int
```

The ASN.1 item's tag as a integer value. The integer values for possible tags are as follows:

```
boolean (1)
integer (2)
bitString (3)
octets (4)
null (5)
oid (6)
utf8String (12)
relativeOid (13)
sequence (16)
set (17)
numericString (18)
printableString (19)
t61String (20)
ia5String (22)
utcTime (23)
bmpString (30)
```

## Methods

### Asn.AppendBigInt

`Chilkat 11.7.0 · b4x · Asn · AppendBigInt · method · since 9.5.0.49`

```visual-basic
AppendBigInt (encodedBytes As String, encoding As String) As Boolean
```

Appends an ASN.1 integer, but one that is a big (huge) integer that is too large to be represented by an integer variable. The bytes composing the integer are passed in encoded string format (such as base64, hex, etc.). The byte order must be big-endian. The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns True for success, False for failure.

### Asn.AppendBits

`Chilkat 11.7.0 · b4x · Asn · AppendBits · method · since 9.5.0.49`

```visual-basic
AppendBits (encodedBytes As String, encoding As String) As Boolean
```

Appends an ASN.1 bit string to the caller's sub-items. The bytes containing the bits are passed in encoded string format (such as base64, hex, etc.). The byte order must be big-endian (MSB first). The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns True for success, False for failure.

### Asn.AppendBool

`Chilkat 11.7.0 · b4x · Asn · AppendBool · method · since 9.5.0.49`

```visual-basic
AppendBool (value As Boolean) As Boolean
```

Appends an ASN.1 boolean item to the caller's sub-items. Items may only be appended to constructed data types such as Sequence and Set.

Returns True for success, False for failure.

### Asn.AppendContextConstructed

`Chilkat 11.7.0 · b4x · Asn · AppendContextConstructed · method · since 9.5.0.50`

```visual-basic
AppendContextConstructed (tag As Int) As Boolean
```

Appends an ASN.1 context-specific constructed item to the caller's sub-items.

Returns True for success, False for failure.

### Asn.AppendContextPrimitive

`Chilkat 11.7.0 · b4x · Asn · AppendContextPrimitive · method · since 9.5.0.50`

```visual-basic
AppendContextPrimitive (tag As Int, encodedBytes As String, encoding As String) As Boolean
```

Appends an ASN.1 context-specific primitive item to the caller's sub-items. The bytes are passed in encoded string format (such as base64, hex, etc.). The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns True for success, False for failure.

### Asn.AppendInt

`Chilkat 11.7.0 · b4x · Asn · AppendInt · method · since 9.5.0.49`

```visual-basic
AppendInt (value As Int) As Boolean
```

Appends an ASN.1 integer item to the caller's sub-items. Items may only be appended to constructed data types such as Sequence and Set.

Returns True for success, False for failure.

### Asn.AppendNull

`Chilkat 11.7.0 · b4x · Asn · AppendNull · method · since 9.5.0.49`

```visual-basic
AppendNull As Boolean
```

Appends an ASN.1 null item to the caller's sub-items. Items may only be appended to constructed data types such as Sequence and Set.

Returns True for success, False for failure.

### Asn.AppendOctets

`Chilkat 11.7.0 · b4x · Asn · AppendOctets · method · since 9.5.0.49`

```visual-basic
AppendOctets (encodedBytes As String, encoding As String) As Boolean
```

Appends an ASN.1 octet string to the caller's sub-items. The bytes are passed in encoded string format (such as base64, hex, etc.). The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns True for success, False for failure.

### Asn.AppendOid

`Chilkat 11.7.0 · b4x · Asn · AppendOid · method · since 9.5.0.49`

```visual-basic
AppendOid (oid As String) As Boolean
```

Appends an ASN.1 OID (object identifier) to the caller's sub-items. The OID is passed in string form, such as `1.2.840.113549.1.9.1`.

Returns True for success, False for failure.

### Asn.AppendSequence

`Chilkat 11.7.0 · b4x · Asn · AppendSequence · method · since 9.5.0.49`

```visual-basic
AppendSequence As Boolean
```

Appends an ASN.1 sequence item to the caller's sub-items.

Returns True for success, False for failure.

### Asn.AppendSequence2

`Chilkat 11.7.0 · b4x · Asn · AppendSequence2 · method · since 9.5.0.50`

```visual-basic
AppendSequence2 As Boolean
```

Appends an ASN.1 sequence item to the caller's sub-items, and updates the internal reference to point to the newly appended sequence item.

Returns True for success, False for failure.

### Asn.AppendSequenceR

`Chilkat 11.7.0 · b4x · Asn · AppendSequenceR · method · since 9.5.0.50`

```visual-basic
AppendSequenceR As ChilkatAsn
```

Appends an ASN.1 sequence item to the caller's sub-items, and returns the newly appended sequence item.

Returns `Null` on failure

### Asn.AppendSet

`Chilkat 11.7.0 · b4x · Asn · AppendSet · method · since 9.5.0.49`

```visual-basic
AppendSet As Boolean
```

Appends an ASN.1 set item to the caller's sub-items.

Returns True for success, False for failure.

### Asn.AppendSet2

`Chilkat 11.7.0 · b4x · Asn · AppendSet2 · method · since 9.5.0.50`

```visual-basic
AppendSet2 As Boolean
```

Appends an ASN.1 set item to the caller's sub-items, and updates the internal reference to point to the newly appended set item.

Returns True for success, False for failure.

### Asn.AppendSetR

`Chilkat 11.7.0 · b4x · Asn · AppendSetR · method · since 9.5.0.50`

```visual-basic
AppendSetR As ChilkatAsn
```

Appends an ASN.1 set item to the caller's sub-items, and returns the newly appended set item.

Returns `Null` on failure

### Asn.AppendString

`Chilkat 11.7.0 · b4x · Asn · AppendString · method · since 9.5.0.49`

```visual-basic
AppendString (strType As String, value As String) As Boolean
```

Appends a string item to the caller's sub-items. The `strType` specifies the type of string to be added. It may be `utf8`, `ia5`, `t61`, `printable`, `visible`, `numeric`, `universal`, or `bmp`. The `value` must conform to the ASN.1 restrictions imposed for a given string type. The `utf8`, `bmp`, and `universal` types have no restrictions on what characters are allowed. In general, unless a specific type of string is required, choose the `utf8` type.

Returns True for success, False for failure.

### Asn.AppendTime

`Chilkat 11.7.0 · b4x · Asn · AppendTime · method · since 9.5.0.49`

```visual-basic
AppendTime (timeFormat As String, dateTimeStr As String) As Boolean
```

Appends a UTCTime item to the caller's sub-items. The `timeFormat` specifies the format of the `dateTimeStr`. It should be set to `utc`. (In the future, this method will be expanded to append GeneralizedTime items by using `generalized` for `timeFormat`.) To append the current date/time, set `dateTimeStr` equal to the empty string or the keyword `now`. Otherwise, the `dateTimeStr` should be in the UTC time format `YYMMDDhhmm[ss]Z` or `YYMMDDhhmm[ss](+|-)hhmm`.

Returns True for success, False for failure.

### Asn.AsnToXml

`Chilkat 11.7.0 · b4x · Asn · AsnToXml · method · since 9.5.0.49`

```visual-basic
AsnToXml As String
```

Converts ASN.1 to XML and returns the XML string.

Returns `Null` on failure

### Asn.DeleteSubItem

`Chilkat 11.7.0 · b4x · Asn · DeleteSubItem · method · since 9.5.0.49`

```visual-basic
DeleteSubItem (index As Int) As Boolean
```

Discards the Nth sub-item. (The 1st sub-item is at index 0.)

Returns True for success, False for failure.

### Asn.GetEncodedContent

`Chilkat 11.7.0 · b4x · Asn · GetEncodedContent · method · since 9.5.0.49`

```visual-basic
GetEncodedContent (encoding As String) As String
```

Returns the content of the ASN.1 item in encoded string form. The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns `Null` on failure

### Asn.GetEncodedDer

`Chilkat 11.7.0 · b4x · Asn · GetEncodedDer · method · since 9.5.0.49`

```visual-basic
GetEncodedDer (encoding As String) As String
```

Returns the binary DER in encoded string form. The `encoding` indicates the encoding and can be `base64`, `hex`, `uu`, `quoted-printable`, `base32`, or `modbase64`.

Returns `Null` on failure

### Asn.GetLastSubItem

`Chilkat 11.7.0 · b4x · Asn · GetLastSubItem · method · since 9.5.0.49`

```visual-basic
GetLastSubItem As ChilkatAsn
```

Returns the last ASN.1 sub-item. This method can be called immediately after any Append\* method to access the appended item.

Returns `Null` on failure

### Asn.GetSubItem

`Chilkat 11.7.0 · b4x · Asn · GetSubItem · method · since 9.5.0.49`

```visual-basic
GetSubItem (index As Int) As ChilkatAsn
```

Returns the Nth ASN.1 sub-item. The 1st sub-item is at index 0.

Returns `Null` on failure

### Asn.LoadAsnXml

`Chilkat 11.7.0 · b4x · Asn · LoadAsnXml · method · since 9.5.0.49`

```visual-basic
LoadAsnXml (xmlStr As String) As Boolean
```

Loads ASN.1 from the XML representation (such as that created by the AsnToXml method).

Returns True for success, False for failure.

### Asn.LoadBd

`Chilkat 11.7.0 · b4x · Asn · LoadBd · method · since 9.5.0.77`

```visual-basic
LoadBd (bd As ChilkatBinData) As Boolean
```

Loads ASN.1 from the binary DER contained in `bd`.

Returns True for success, False for failure.

### Asn.LoadBinaryFile

`Chilkat 11.7.0 · b4x · Asn · LoadBinaryFile · method · since 9.5.0.49`

```visual-basic
LoadBinaryFile (path As String) As Boolean
```

Loads ASN.1 from a binary DER file.

Returns True for success, False for failure.

### Asn.LoadEncoded

`Chilkat 11.7.0 · b4x · Asn · LoadEncoded · method · since 9.5.0.49`

```visual-basic
LoadEncoded (asnContent As String, encoding As String) As Boolean
```

Loads ASN.1 from an encoded string. The `encoding` can be `base64`, `hex`, `uu`, `quoted-printable`, `base32`, or `modbase64`.

Returns True for success, False for failure.

### Asn.SetEncodedContent

`Chilkat 11.7.0 · b4x · Asn · SetEncodedContent · method · since 9.5.0.49`

```visual-basic
SetEncodedContent (encodedBytes As String, encoding As String) As Boolean
```

Sets the content of this primitive ASN.1 item. The `encoding` may be any of the following encodings: `Base64`, `Hex`, `Base58`, `modBase64`, `Base32`, `UU`, `QP` (for quoted-printable), `URL` (for url-encoding), `Q`, `B`, `url_oath`, `url_rfc1738`, `url_rfc2396`, and `url_rfc3986`. The `encoding` name is case insensitive (for example, both `Base64` and `base64` are treated the same).

Returns True for success, False for failure.

### Asn.WriteBd

`Chilkat 11.7.0 · b4x · Asn · WriteBd · method · since 9.5.0.77`

```visual-basic
WriteBd (bd As ChilkatBinData) As Boolean
```

Appends the ASN.1 in binary DER format to `bd`.

Returns True for success, False for failure.

### Asn.WriteBinaryDer

`Chilkat 11.7.0 · b4x · Asn · WriteBinaryDer · method · since 9.5.0.49`

```visual-basic
WriteBinaryDer (path As String) As Boolean
```

Writes the ASN.1 in binary DER form to a file.

Returns True for success, False for failure.

## Related classes

[`BinData`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/b4x/classes/BinData.md)

