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

Abandoned → [genkgo/php-asn1](/?search=genkgo%2Fphp-asn1)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

uma/phpasn1
===========

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

v2.5.1(1y ago)04.3k↑50%1MITPHPPHP ^8.1CI passing

Since Nov 29Pushed 1y agoCompare

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

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

PHPASN1
=======

[](#phpasn1)

[![PHPUnit](https://github.com/1ma/PHPASN1/actions/workflows/phpunit.yml/badge.svg)](https://github.com/1ma/PHPASN1/actions/workflows/phpunit.yml)[![Latest Stable Version](https://camo.githubusercontent.com/0602a629ddbb9ea134b8ef36f0afaed8987c33f0b3c3ce06c80d59331c7719b7/68747470733a2f2f706f7365722e707567782e6f72672f6667726f7373652f70687061736e312f762f737461626c652e706e67)](https://packagist.org/packages/fgrosse/phpasn1)[![Total Downloads](https://camo.githubusercontent.com/a34fb9d5f301b24025f78d4ae2522332b3f3671e204852b950236fac93340c40/68747470733a2f2f706f7365722e707567782e6f72672f6667726f7373652f70687061736e312f646f776e6c6f6164732e706e67)](https://packagist.org/packages/fgrosse/phpasn1)[![License](https://camo.githubusercontent.com/6c52d94205f7a845f1ba55b89a2e6bbc6893e6a0d350d381c6788651113d2f28/68747470733a2f2f706f7365722e707567782e6f72672f6667726f7373652f70687061736e312f6c6963656e73652e706e67)](https://packagist.org/packages/fgrosse/phpasn1)

---

This is a fork to support [uma/phpecc](https://github.com/1ma/phpecc/) and in turn [nostrver-se/nostr-php](https://github.com/nostrver-se/nostr-php).

It is abandoned, use [`genkgo/php-asn1`](https://github.com/genkgo/php-asn1) instead.

---

Notice: This library is no longer actively maintained!
------------------------------------------------------

[](#notice-this-library-is-no-longer-actively-maintained)

If you are currently using PHPASN1, this might not be an immediate problem for you, since this library was always rather stable. However, you are advised to migrate to alternative packages to ensure that your applications remain functional also with newer PHP versions.

Another option is to fork this repository or use [one of the existing forks](https://github.com/fgrosse/PHPASN1/forks?include=active&page=1&period=2y&sort_by=last_updated).

⚠ **If you are using another fork, please make sure you trust the author** and validate the code you are relying upon!

---

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.0` and either the `gmp` or `bcmath` extension. Support for older PHP versions (i.e. PHP 5.6) was dropped starting with `v2.0`. If you must use an outdated PHP version consider using [PHPASN v1.5](https://packagist.org/packages/fgrosse/phpasn1#1.5.2).

For the loading of object identifier names directly from the web [curl](http://php.net/manual/en/book.curl.php) is used.

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

[](#installation)

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

```
$ composer require uma/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\OID;
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 = new Integer(123456);
$boolean = new Boolean(true);
$enum = new Enumerated(1);
$ia5String = new IA5String('Hello world');

$asnNull = new NullObject();
$objectIdentifier1 = new ObjectIdentifier('1.2.250.1.16.9');
$objectIdentifier2 = new ObjectIdentifier(OID::RSA_ENCRYPTION);
$printableString = new PrintableString('Foo bar');

$sequence = new Sequence($integer, $boolean, $enum, $ia5String);
$set = new 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\ASNObject;

$base64String = ...
$binaryData = base64_decode($base64String);
$asnObject = ASNObject::fromBinary($binaryData);

// do stuff
```

If you already know exactly how your expected data should look like you can use the `FG\ASN1\TemplateParser`:

```
use FG\ASN1\TemplateParser;

// first define your template
$template = [
    Identifier::SEQUENCE => [
        Identifier::SET => [
            Identifier::OBJECT_IDENTIFIER,
            Identifier::SEQUENCE => [
                Identifier::INTEGER,
                Identifier::BITSTRING,
            ]
        ]
    ]
];

// if your binary data is not matching the template you provided this will throw an `\Exception`:
$parser = new TemplateParser();
$object = $parser->parseBinary($data, $template);

// there is also a convenience function if you parse binary data from base64:
$object = $parser->parseBase64($data, $template);
```

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

### Navigating decoded data

[](#navigating-decoded-data)

All constructed classes (i.e. `Sequence` and `Set`) can be navigated by array access or using an iterator. You can find examples [here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/Universal/SequenceTest.php#L148-148), [here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/Universal/SequenceTest.php#L121) and [here](https://github.com/fgrosse/PHPASN1/blob/f6442cadda9d36f3518c737e32f28300a588b777/tests/ASN1/TemplateParserTest.php#L45).

### Give me more examples!

[](#give-me-more-examples)

To see some example usage of the API classes or some generated output check out the [examples](https://github.com/fgrosse/PHPASN1/tree/master/examples).

### How do I contribute?

[](#how-do-i-contribute)

This project is no longer maintained and thus does not accept any new contributions.

### Thanks

[](#thanks)

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

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance40

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.2% 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

Unknown

Total

1

Last Release

535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e9c44fd950318b0691210b9e372cfaae750d5d6a0b37500676ff636b3a58f1f?d=identicon)[1ma](/maintainers/1ma)

---

Top Contributors

[![fgrosse](https://avatars.githubusercontent.com/u/733004?v=4)](https://github.com/fgrosse "fgrosse (188 commits)")[![afk11](https://avatars.githubusercontent.com/u/5617245?v=4)](https://github.com/afk11 "afk11 (16 commits)")[![TimWolla](https://avatars.githubusercontent.com/u/209270?v=4)](https://github.com/TimWolla "TimWolla (14 commits)")[![nathanntg](https://avatars.githubusercontent.com/u/194728?v=4)](https://github.com/nathanntg "nathanntg (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)")[![1ma](https://avatars.githubusercontent.com/u/1456708?v=4)](https://github.com/1ma "1ma (4 commits)")[![sanderkruger](https://avatars.githubusercontent.com/u/1422536?v=4)](https://github.com/sanderkruger "sanderkruger (4 commits)")[![Blaimi](https://avatars.githubusercontent.com/u/1222379?v=4)](https://github.com/Blaimi "Blaimi (3 commits)")[![devicenull](https://avatars.githubusercontent.com/u/58017?v=4)](https://github.com/devicenull "devicenull (1 commits)")[![oRastor](https://avatars.githubusercontent.com/u/1734394?v=4)](https://github.com/oRastor "oRastor (1 commits)")[![PhilETaylor](https://avatars.githubusercontent.com/u/400092?v=4)](https://github.com/PhilETaylor "PhilETaylor (1 commits)")[![bilogic](https://avatars.githubusercontent.com/u/946010?v=4)](https://github.com/bilogic "bilogic (1 commits)")[![staabm](https://avatars.githubusercontent.com/u/120441?v=4)](https://github.com/staabm "staabm (1 commits)")[![Tatikoma](https://avatars.githubusercontent.com/u/1888609?v=4)](https://github.com/Tatikoma "Tatikoma (1 commits)")[![lcts](https://avatars.githubusercontent.com/u/6643758?v=4)](https://github.com/lcts "lcts (1 commits)")[![herndlm](https://avatars.githubusercontent.com/u/5738896?v=4)](https://github.com/herndlm "herndlm (1 commits)")

---

Tags

x509asn1encodingDERx690binarydecodingber

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/uma-phpasn1/health.svg)](https://phpackages.com/packages/uma-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)
