PHPackages                             adapik/phpasn1 - 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. adapik/phpasn1

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

adapik/phpasn1
==============

A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules.

2.4.2(6mo ago)48.6k↓20.6%4[4 issues](https://github.com/Adapik/PHPASN1/issues)2MITPHPPHP &gt;=7.4CI passing

Since Feb 3Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/Adapik/PHPASN1)[ Packagist](https://packagist.org/packages/adapik/phpasn1)[ Docs](https://github.com/Adapik/PHPASN1)[ RSS](/packages/adapik-phpasn1/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (33)Used By (2)

PHPASN1
=======

[](#phpasn1)

[![build status](https://github.com/adapik/PHPASN1/actions/workflows/tests.yaml/badge.svg?branch=master)](https://github.com/adapik/PHPASN1/actions/workflows/tests.yaml/badge.svg?branch=master)[![codecov](https://camo.githubusercontent.com/af9bb9f01a3bd7d79fd57c44eb1d44697e10001f25ba1e5c530d034262da83f6/68747470733a2f2f636f6465636f762e696f2f6769746875622f61646170696b2f70687061736e312f67726170682f62616467652e7376673f746f6b656e3d4b434248374556324a30)](https://codecov.io/github/adapik/phpasn1)

[![Latest Stable Version](https://camo.githubusercontent.com/a9551704d84b20af11759d5a04278c26508a4c3f11d6f747af502b8784c54fbe/68747470733a2f2f706f7365722e707567782e6f72672f41646170696b2f70687061736e312f762f737461626c652e706e67)](https://packagist.org/packages/Adapik/phpasn1)[![Total Downloads](https://camo.githubusercontent.com/311c73dbc85f7c13aba45f514eea7af5458c05eba6d84dc9f428ea835129879d/68747470733a2f2f706f7365722e707567782e6f72672f41646170696b2f70687061736e312f646f776e6c6f6164732e706e67)](https://packagist.org/packages/Adapik/phpasn1)[![License](https://camo.githubusercontent.com/32d94c004858d8b206e6499ed6c3589a45d2b8af49fee12ad5bbe1b7c3f04457/68747470733a2f2f706f7365722e707567782e6f72672f41646170696b2f70687061736e312f6c6963656e73652e706e67)](https://packagist.org/packages/Adapik/phpasn1)

A PHP Framework that allows you to encode and decode arbitrary [ASN.1](http://www.itu.int/ITU-T/asn1/) structures using the [ITU-T X.690 Encoding Rules](http://www.itu.int/ITU-T/recommendations/rec.aspx?rec=x.690). This encoding is very frequently used in [X.509 PKI environments](http://en.wikipedia.org/wiki/X.509) or the communication between heterogeneous computer systems.

The API allows you to encode ASN.1 structures to create binary data such as certificate signing requests (CSR), X.509 certificates or certificate revocation lists (CRL). PHPASN1 can also read [BER encoded](http://en.wikipedia.org/wiki/X.690#BER_encoding) binary data into separate PHP objects that can be manipulated by the user and reencoded afterwards.

The **changelog** can now be found at [CHANGELOG.md](CHANGELOG.md).

Dependencies
------------

[](#dependencies)

PHPASN1 requires at least `PHP 7` and the `gmp` extension.

Installation
------------

[](#installation)

The preferred way to install this library is to rely on [Composer](https://getcomposer.org/):

```
$ composer require Adapik/phpasn1
```

Usage
-----

[](#usage)

### Encoding ASN.1 Structures

[](#encoding-asn1-structures)

PHPASN1 offers you a class for each of the implemented ASN.1 universal types. The constructors should be pretty self explanatory so you should have no big trouble getting started. All data will be encoded using [DER encoding](http://en.wikipedia.org/wiki/X.690#DER_encoding)

```
use FG\ASN1\Universal\Integer;
use FG\ASN1\Universal\Boolean;
use FG\ASN1\Universal\Enumerated;
use FG\ASN1\Universal\IA5String;
use FG\ASN1\Universal\ObjectIdentifier;
use FG\ASN1\Universal\PrintableString;
use FG\ASN1\Universal\Sequence;
use FG\ASN1\Universal\Set;
use FG\ASN1\Universal\NullObject;

$integer = Integer::create(123456);
$boolean = Boolean::create(true);
$enum = Enumerated::create(1);

$asnNull = NullObject::create();
$objectIdentifier1 = ObjectIdentifier('1.2.250.1.16.9');
$printableString = PrintableString::createFromString('Foo bar');

$sequence = Sequence::create([$integer, $boolean, $enum, $ia5String]);
$set = Set([$sequence, $asnNull, $objectIdentifier1, $objectIdentifier2, $printableString]);

$myBinary  = $sequence->getBinary();
$myBinary .= $set->getBinary();

echo base64_encode($myBinary);
```

### Decoding binary data

[](#decoding-binary-data)

Decoding BER encoded binary data is just as easy as encoding it:

```
use FG\ASN1\Object;

$base64String = ...
$binaryData = base64_decode($base64String);
$asnObject = Object::fromBinary($binaryData);
// do stuff
```

You can use this function to make sure your data has exactly the format you are expecting.

### Thanks

[](#thanks)

To [all contributors](https://github.com/Adapik/PHPASN1/graphs/contributors) so far!

License
-------

[](#license)

This library is distributed under the [MIT License](LICENSE).

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance46

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 60.1% 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 ~170 days

Recently: every ~415 days

Total

24

Last Release

196d ago

Major Versions

0.9.0 → 1.0.02015-02-03

1.5.1 → 2.0.02017-07-13

PHP version history (6 changes)0.9.0PHP &gt;=5.3.0

1.4.0PHP &gt;=5.6.0

2.0.0PHP &gt;=7.0

2.1PHP &gt;=7.1

2.3PHP &gt;=7.2

2.4.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1821443b57ce700a2c6c9615108815ac188170cac9ba8edfe08aa0ae38da5f3?d=identicon)[Adapik](/maintainers/Adapik)

---

Top Contributors

[![fgrosse](https://avatars.githubusercontent.com/u/733004?v=4)](https://github.com/fgrosse "fgrosse (146 commits)")[![adapik](https://avatars.githubusercontent.com/u/10532067?v=4)](https://github.com/adapik "adapik (43 commits)")[![Falseclock](https://avatars.githubusercontent.com/u/3299139?v=4)](https://github.com/Falseclock "Falseclock (22 commits)")[![afk11](https://avatars.githubusercontent.com/u/5617245?v=4)](https://github.com/afk11 "afk11 (12 commits)")[![kgilden](https://avatars.githubusercontent.com/u/918599?v=4)](https://github.com/kgilden "kgilden (10 commits)")[![Naugrimm](https://avatars.githubusercontent.com/u/5753604?v=4)](https://github.com/Naugrimm "Naugrimm (5 commits)")[![Blaimi](https://avatars.githubusercontent.com/u/1222379?v=4)](https://github.com/Blaimi "Blaimi (3 commits)")[![bashkarev](https://avatars.githubusercontent.com/u/3738201?v=4)](https://github.com/bashkarev "bashkarev (1 commits)")[![Tatikoma](https://avatars.githubusercontent.com/u/1888609?v=4)](https://github.com/Tatikoma "Tatikoma (1 commits)")

---

Tags

x509asn1encodingDERx690binarydecodingber

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adapik-phpasn1/health.svg)

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

###  Alternatives

[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.2k](/packages/falseclock-advanced-cms)[paragonie/constant_time_encoding

Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)

903329.7M148](/packages/paragonie-constant-time-encoding)[adapik/cms

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

147.2k1](/packages/adapik-cms)[kelunik/certificate

Access certificate details and transform between different formats.

11038.3M8](/packages/kelunik-certificate)[freedsx/asn1

An ASN.1 library for PHP.

15216.5k9](/packages/freedsx-asn1)[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.

2725.9M11](/packages/spomky-labs-pki-framework)

PHPackages © 2026

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