PHPackages                             freedsx/asn1 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. freedsx/asn1

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

freedsx/asn1
============

An ASN.1 library for PHP.

0.4.8(1y ago)15245.4k↑50%3[3 issues](https://github.com/FreeDSx/ASN1/issues)7MITPHPPHP &gt;=7.1CI passing

Since Apr 14Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/FreeDSx/ASN1)[ Packagist](https://packagist.org/packages/freedsx/asn1)[ Docs](https://github.com/FreeDSx/ASN1)[ RSS](/packages/freedsx-asn1/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (3)Dependencies (6)Versions (22)Used By (7)

FreeDSx ASN1 [![](https://github.com/FreeDSx/ASN1/workflows/Analysis/badge.svg)](https://github.com/FreeDSx/ASN1/workflows/Analysis/badge.svg) [![](https://github.com/FreeDSx/ASN1/workflows/Build/badge.svg)](https://github.com/FreeDSx/ASN1/workflows/Build/badge.svg) [![codecov](https://camo.githubusercontent.com/9ab268fa8ed5bb5af0f57df914e220c42734507a8f8b26ad1673236a9c5a6beb/68747470733a2f2f636f6465636f762e696f2f67682f467265654453782f41534e312f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/FreeDSx/ASN1)
=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#freedsx-asn1---)

FreeDSx ASN1 is a PHP library for dealing with ASN.1 data structures. Its original focus was on ASN.1 BER encoding used in LDAP as part of the FreeDSx LDAP library. It was moved to its own library to allow for additional encoders and reuse in other projects.

Getting Started
===============

[](#getting-started)

Install via composer:

```
composer require freedsx/asn1
```

Encoding
--------

[](#encoding)

To encode an ASN.1 structure you can use the helper methods of the Asn1 class and an encoder:

```
use FreeDSx\Asn1\Asn1;
use FreeDSx\Asn1\Encoders;

# Create the ASN.1 structure you need...
$asn1 = Asn1::sequence(
    Asn1::integer(9999),
    Asn1::octetString('foo'),
    Asn1::boolean(true)
);

# Encoded $bytes will now contain the BER binary representation of a sequence containing:
#  - An integer type of value 9999
#  - An octet string type of value 'foo'
#  - A boolean type of true
$bytes = Encoders::ber()->encode($asn1);

# Encode using the more strict DER encoder
$bytes = Encoders::der()->encode($asn1);
```

Decoding
--------

[](#decoding)

To decode an ASN.1 structure you can get an encoder and call decode then parse it out:

```
use FreeDSx\Asn1\Asn1;
use FreeDSx\Asn1\Encoders;
use FreeDSx\Asn1\Type\SequenceType;
use FreeDSx\Asn1\Type\OctetStringType;
use FreeDSx\Asn1\Type\IntegerType;
use FreeDSx\Asn1\Type\BooleanType;

# Assuming bytes contains the binary BER encoded sequence described in the encoding section
# Get a BER encoder instance, call decode on it, and $pdu will now be a sequence object.
$pdu = Encoders::ber()->decode($bytes);

# You could also decode using DER, if that's what you're expecting...
$pdu = Encoders::der()->decode($bytes);

# Validate the structure you are expecting...
if (!($pdu instanceof SequenceType && count($pdu) === 3)) {
    echo "Decoded structure is invalid.".PHP_EOL;
    exit;
}

# Loop through the sequence and check the individual types it contains...
foreach ($pdu as $i => $type) {
    if ($i === 0 && $type instanceof IntegerType) {
        var_dump($type->getValue());
    } elseif ($i === 1 && $type instanceof OctetStringType) {
        var_dump($type->getValue());
    } elseif ($i === 2 && $type instanceof BooleanType) {
        var_dump($type->getValue());
    } else {
        echo "Invalid type encountered.".PHP_EOL;
        exit;
    }
}
```

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~169 days

Recently: every ~367 days

Total

15

Last Release

628d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/388229?v=4)[Chad Sikorra](/maintainers/ChadSikorra)[@ChadSikorra](https://github.com/ChadSikorra)

---

Top Contributors

[![ChadSikorra](https://avatars.githubusercontent.com/u/388229?v=4)](https://github.com/ChadSikorra "ChadSikorra (129 commits)")

---

Tags

asn1berderphpx690asn1DERx690ber

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/freedsx-asn1/health.svg)

```
[![Health](https://phpackages.com/badges/freedsx-asn1/health.svg)](https://phpackages.com/packages/freedsx-asn1)
```

###  Alternatives

[kelunik/certificate

Access certificate details and transform between different formats.

11145.9M13](/packages/kelunik-certificate)[falseclock/advanced-cms

A PHP Library that allows you to decode and manipulate CAdES or in other words CMS Advanced Electronic Signatures described in ETSI standart TS 101 733.

223.5k](/packages/falseclock-advanced-cms)[adapik/cms

A PHP Library that allows you to decode ASN.1 CMS using Basic Encoding Rules (BER).

148.1k1](/packages/adapik-cms)[spomky-labs/pki-framework

A PHP framework for managing Public Key Infrastructures. It comprises X.509 public key certificates, attribute certificates, certification requests and certification path validation.

2735.6M23](/packages/spomky-labs-pki-framework)[sop/asn1

A PHP library for X.690 ASN.1 DER encoding and decoding.

621.8M41](/packages/sop-asn1)[sop/crypto-types

A PHP library of various ASN.1 types for cryptographic applications.

121.4M35](/packages/sop-crypto-types)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
