---
product: Chilkat
product_version: 11.7.0
language: phpx
language_label: PHP ActiveX
class: Asn
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/phpAsnRef.html
---
# Chilkat Asn — PHP ActiveX — v11.7.0

> Chilkat 11.7.0 · language=phpx · class=Asn
> 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/phpx/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

**Object Creation**

```php
Chilkat v10.0.0 or greater:
$obj = new COM("Chilkat.Asn");
Chilkat v9.5.0.*:
$obj = new COM("Chilkat_9_5_0.Asn");
```

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 PHP ActiveX.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## 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` | `string DebugLogFilePath` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `VARIANT LastBinaryResult (read-only)` | read-only | This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. |
| `LastErrorHtml` | `string LastErrorHtml (read-only)` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `string LastErrorText (read-only)` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `string LastErrorXml (read-only)` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `bool LastMethodSuccess` | read/write | Indicates the success or failure of the most recent method call: `true` means success, `false` means failure. |
| `LastStringResult` | `string LastStringResult (read-only)` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `int LastStringResultLen (read-only)` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `bool VerboseLogging` | read/write | If set to `true`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `string Version (read-only)` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `BoolValue` | property, read/write | `bool BoolValue` |
| `Constructed` | property, read-only | `bool Constructed (read-only)` |
| `ContentStr` | property, read/write | `string ContentStr` |
| `IntValue` | property, read/write | `int IntValue` |
| `NumSubItems` | property, read-only | `int NumSubItems (read-only)` |
| `Tag` | property, read-only | `string Tag (read-only)` |
| `TagValue` | property, read-only | `int TagValue (read-only)` |
| `AppendBigInt` | method | `bool AppendBigInt(string encodedBytes, string encoding)` |
| `AppendBits` | method | `bool AppendBits(string encodedBytes, string encoding)` |
| `AppendBool` | method | `bool AppendBool(bool value)` |
| `AppendContextConstructed` | method | `bool AppendContextConstructed(int tag)` |
| `AppendContextPrimitive` | method | `bool AppendContextPrimitive(int tag, string encodedBytes, string encoding)` |
| `AppendInt` | method | `bool AppendInt(int value)` |
| `AppendNull` | method | `bool AppendNull()` |
| `AppendOctets` | method | `bool AppendOctets(string encodedBytes, string encoding)` |
| `AppendOid` | method | `bool AppendOid(string oid)` |
| `AppendSequence` | method | `bool AppendSequence()` |
| `AppendSequence2` | method | `bool AppendSequence2()` |
| `AppendSequenceR` | method | `Chilkat.Asn AppendSequenceR()` |
| `AppendSet` | method | `bool AppendSet()` |
| `AppendSet2` | method | `bool AppendSet2()` |
| `AppendSetR` | method | `Chilkat.Asn AppendSetR()` |
| `AppendString` | method | `bool AppendString(string strType, string value)` |
| `AppendTime` | method | `bool AppendTime(string timeFormat, string dateTimeStr)` |
| `AsnToXml` | method | `string AsnToXml()` |
| `DeleteSubItem` | method | `bool DeleteSubItem(int index)` |
| `GetBinaryDer` | method | `VARIANT GetBinaryDer()` |
| `GetEncodedContent` | method | `string GetEncodedContent(string encoding)` |
| `GetEncodedDer` | method | `string GetEncodedDer(string encoding)` |
| `GetLastSubItem` | method | `Chilkat.Asn GetLastSubItem()` |
| `GetSubItem` | method | `Chilkat.Asn GetSubItem(int index)` |
| `LoadAsnXml` | method | `bool LoadAsnXml(string xmlStr)` |
| `LoadBd` | method | `bool LoadBd(Chilkat.BinData bd)` |
| `LoadBinary` | method | `bool LoadBinary(VARIANT derBytes)` |
| `LoadBinaryFile` | method | `bool LoadBinaryFile(string path)` |
| `LoadEncoded` | method | `bool LoadEncoded(string asnContent, string encoding)` |
| `SetEncodedContent` | method | `bool SetEncodedContent(string encodedBytes, string encoding)` |
| `WriteBd` | method | `bool WriteBd(Chilkat.BinData bd)` |
| `WriteBinaryDer` | method | `bool WriteBinaryDer(string path)` |

## Properties

### Asn.BoolValue

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

```php
bool BoolValue
```

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

### Asn.Constructed

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

```php
bool Constructed (read-only)
```

`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 · phpx · Asn · ContentStr · property · read/write · since 9.5.0.49`

```php
string ContentStr
```

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 · phpx · Asn · IntValue · property · read/write · since 9.5.0.49`

```php
int IntValue
```

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

### Asn.NumSubItems

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

```php
int NumSubItems (read-only)
```

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 · phpx · Asn · Tag · property · read-only · since 9.5.0.49`

```php
string Tag (read-only)
```

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 · phpx · Asn · TagValue · property · read-only · since 9.5.0.49`

```php
int TagValue (read-only)
```

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 · phpx · Asn · AppendBigInt · method · since 9.5.0.49`

```php
bool AppendBigInt(string encodedBytes, string encoding)
```

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 · phpx · Asn · AppendBits · method · since 9.5.0.49`

```php
bool AppendBits(string encodedBytes, string encoding)
```

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 · phpx · Asn · AppendBool · method · since 9.5.0.49`

```php
bool AppendBool(bool value)
```

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 · phpx · Asn · AppendContextConstructed · method · since 9.5.0.50`

```php
bool AppendContextConstructed(int tag)
```

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 · phpx · Asn · AppendContextPrimitive · method · since 9.5.0.50`

```php
bool AppendContextPrimitive(int tag, string encodedBytes, string encoding)
```

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 · phpx · Asn · AppendInt · method · since 9.5.0.49`

```php
bool AppendInt(int value)
```

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 · phpx · Asn · AppendNull · method · since 9.5.0.49`

```php
bool AppendNull()
```

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 · phpx · Asn · AppendOctets · method · since 9.5.0.49`

```php
bool AppendOctets(string encodedBytes, string encoding)
```

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 · phpx · Asn · AppendOid · method · since 9.5.0.49`

```php
bool AppendOid(string oid)
```

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 · phpx · Asn · AppendSequence · method · since 9.5.0.49`

```php
bool AppendSequence()
```

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 · phpx · Asn · AppendSequence2 · method · since 9.5.0.50`

```php
bool AppendSequence2()
```

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 · phpx · Asn · AppendSequenceR · method · since 9.5.0.50`

```php
Chilkat.Asn AppendSequenceR()
```

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 · phpx · Asn · AppendSet · method · since 9.5.0.49`

```php
bool AppendSet()
```

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 · phpx · Asn · AppendSet2 · method · since 9.5.0.50`

```php
bool AppendSet2()
```

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 · phpx · Asn · AppendSetR · method · since 9.5.0.50`

```php
Chilkat.Asn AppendSetR()
```

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 · phpx · Asn · AppendString · method · since 9.5.0.49`

```php
bool AppendString(string strType, string value)
```

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 · phpx · Asn · AppendTime · method · since 9.5.0.49`

```php
bool AppendTime(string timeFormat, string dateTimeStr)
```

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 · phpx · Asn · AsnToXml · method · since 9.5.0.49`

```php
string AsnToXml()
```

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

Returns `null` on failure

### Asn.DeleteSubItem

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

```php
bool DeleteSubItem(int index)
```

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

Returns true for success, false for failure.

### Asn.GetBinaryDer

`Chilkat 11.7.0 · phpx · Asn · GetBinaryDer · method · since 9.5.0.49`

```php
VARIANT GetBinaryDer()
```

Returns the ASN.1 in binary DER form.

Returns `null` on failure

### Asn.GetEncodedContent

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

```php
string GetEncodedContent(string encoding)
```

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 · phpx · Asn · GetEncodedDer · method · since 9.5.0.49`

```php
string GetEncodedDer(string encoding)
```

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 · phpx · Asn · GetLastSubItem · method · since 9.5.0.49`

```php
Chilkat.Asn GetLastSubItem()
```

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 · phpx · Asn · GetSubItem · method · since 9.5.0.49`

```php
Chilkat.Asn GetSubItem(int index)
```

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 · phpx · Asn · LoadAsnXml · method · since 9.5.0.49`

```php
bool LoadAsnXml(string xmlStr)
```

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 · phpx · Asn · LoadBd · method · since 9.5.0.77`

```php
bool LoadBd(Chilkat.BinData bd)
```

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

Returns true for success, false for failure.

### Asn.LoadBinary

`Chilkat 11.7.0 · phpx · Asn · LoadBinary · method · since 9.5.0.49`

```php
bool LoadBinary(VARIANT derBytes)
```

Loads ASN.1 from binary DER.

Returns true for success, false for failure.

### Asn.LoadBinaryFile

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

```php
bool LoadBinaryFile(string path)
```

Loads ASN.1 from a binary DER file.

Returns true for success, false for failure.

### Asn.LoadEncoded

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

```php
bool LoadEncoded(string asnContent, string encoding)
```

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 · phpx · Asn · SetEncodedContent · method · since 9.5.0.49`

```php
bool SetEncodedContent(string encodedBytes, string encoding)
```

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 · phpx · Asn · WriteBd · method · since 9.5.0.77`

```php
bool WriteBd(Chilkat.BinData bd)
```

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

Returns true for success, false for failure.

### Asn.WriteBinaryDer

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

```php
bool WriteBinaryDer(string path)
```

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/phpx/classes/BinData.md)

