PHPackages                             sop/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. sop/asn1

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

sop/asn1
========

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

4.1.2(1y ago)621.8M↓33.1%11[2 issues](https://github.com/sop/asn1/issues)[2 PRs](https://github.com/sop/asn1/pulls)20MITPHPPHP &gt;=7.2CI failing

Since Apr 12Pushed 1y ago6 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (32)Used By (20)

[ASN.1](https://sop.github.io/asn1/)
====================================

[](#asn1)

[![Build Status](https://camo.githubusercontent.com/9d923f3ba66643dfd76e642cd7416eb03f892f42ea605c2cffea2ec1d67ba25b/68747470733a2f2f7472617669732d63692e6f72672f736f702f61736e312e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sop/asn1)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/beb07c377cbc7d231f663689ca99de332ef634f1b639524b6b560a774b59b9a4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f702f61736e312f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sop/asn1/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/5fa7aee3acc0af1b54e806d4fd2201c1299dd6f7bcf55417780377052de1af12/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f736f702f61736e312f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sop/asn1?branch=master)[![License](https://camo.githubusercontent.com/a6ed3ea483d7d5a9f84e3433b4d490a4f37d67aad9e2c0a2631d334cee456388/68747470733a2f2f706f7365722e707567782e6f72672f736f702f61736e312f6c6963656e7365)](https://github.com/sop/asn1/blob/master/LICENSE)

A PHP library for X.690 Abstract Syntax Notation One (ASN.1) Distinguished Encoding Rules (DER) encoding and decoding.

Requirements
------------

[](#requirements)

- PHP &gt;=7.2
- gmp
- mbstring

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

[](#installation)

This library is available on [Packagist](https://packagist.org/packages/sop/asn1).

```
composer require sop/asn1
```

Usage
-----

[](#usage)

The general idea is that each ASN.1 type has its corresponding PHP class, that knows the details of encoding and decoding the specific type.

To decode DER data, use `fromDER` static method of the expected type. To encode object to DER, use `toDER` instance method.

Many methods return an `UnspecifiedType` object, that works as an intermediate wrapper with accessor methods ensuring type safety.

All objects are immutable and method chaining is promoted for the fluency of the API. Exception shall be thrown on errors.

[Code Examples](https://github.com/sop/asn1/tree/master/examples)
-----------------------------------------------------------------

[](#code-examples)

Here are some simple usage examples. Namespaces are omitted for brevity.

### [Encode](https://github.com/sop/asn1/blob/master/examples/encode.php)

[](#encode)

Encode a sequence containing a UTF-8 string, an integer and an explicitly tagged object identifier, conforming to the following ASN.1 specification:

```
Example ::= SEQUENCE {
    greeting    UTF8String,
    answer      INTEGER,
    type    [1] EXPLICIT OBJECT IDENTIFIER
}
```

```
$seq = new Sequence(
    new UTF8String('Hello'),
    new Integer(42),
    new ExplicitlyTaggedType(
        1, new ObjectIdentifier('1.3.6.1.3'))
);
$der = $seq->toDER();
```

### [Decode](https://github.com/sop/asn1/blob/master/examples/decode.php)

[](#decode)

Decode DER encoding from above.

```
$seq = UnspecifiedType::fromDER($der)->asSequence();
$greeting = $seq->at(0)->asUTF8String()->string();
$answer = $seq->at(1)->asInteger()->intNumber();
$type = $seq->at(2)->asTagged()->asExplicit()->asObjectIdentifier()->oid();
```

### Real-World Examples

[](#real-world-examples)

See the following for more practical real-world usage examples.

- EC Private Key
    - [Decode](https://github.com/sop/crypto-types/blob/a27fa76d5f5e8c4596cb65a7be9d02a08421ba1e/lib/CryptoTypes/Asymmetric/EC/ECPrivateKey.php#L72)
    - [Encode](https://github.com/sop/crypto-types/blob/a27fa76d5f5e8c4596cb65a7be9d02a08421ba1e/lib/CryptoTypes/Asymmetric/EC/ECPrivateKey.php#L206)
- X.501 Attribute
    - [Decode](https://github.com/sop/x501/blob/c6bdb04673d5c04b9d49f83020e75b8ba7a20064/lib/X501/ASN1/Attribute.php#L55)
    - [Encode](https://github.com/sop/x501/blob/c6bdb04673d5c04b9d49f83020e75b8ba7a20064/lib/X501/ASN1/Attribute.php#L114)
- X.509 Certificate (`TBSCertificate` sequence)
    - [Decode](https://github.com/sop/x509/blob/f762c743b6930af4f45ef857ccc9f6199980a92e/lib/X509/Certificate/TBSCertificate.php#L130)
    - [Encode](https://github.com/sop/x509/blob/f762c743b6930af4f45ef857ccc9f6199980a92e/lib/X509/Certificate/TBSCertificate.php#L576)

ASN.1 References
----------------

[](#asn1-references)

- [ITU-T X.690 07/2002](https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf)
- [ITU-T X.690 08/2015](https://www.itu.int/rec/T-REC-X.690-201508-I/en)
- Hosted by [OSS Nokalva](http://www.oss.com/asn1/resources/books-whitepapers-pubs/asn1-books.html)
    - [ASN.1 — Communication Between Heterogeneous Systems by Olivier Dubuisson](http://www.oss.com/asn1/resources/books-whitepapers-pubs/dubuisson-asn1-book.PDF)
    - [ASN.1 Complete by Professor John Larmouth](http://www.oss.com/asn1/resources/books-whitepapers-pubs/larmouth-asn1-book.pdf)

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity54

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 97.9% 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 ~110 days

Recently: every ~515 days

Total

30

Last Release

541d ago

Major Versions

1.5.3 → 2.0.02016-06-07

2.0.2 → 3.0.02017-11-03

3.4.3 → 4.0.02019-05-22

PHP version history (3 changes)1.0.0PHP &gt;=5.6.3

3.0.0PHP &gt;=7.0

4.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1017000?v=4)[Joni Kollani](/maintainers/sop)[@sop](https://github.com/sop)

---

Top Contributors

[![sop](https://avatars.githubusercontent.com/u/1017000?v=4)](https://github.com/sop "sop (185 commits)")[![Firehed](https://avatars.githubusercontent.com/u/354842?v=4)](https://github.com/Firehed "Firehed (4 commits)")

---

Tags

asnasn1decodingderencodingparserx690asn1DERx690

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[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)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/packages/mck89-peast)[freedsx/asn1

An ASN.1 library for PHP.

15245.4k13](/packages/freedsx-asn1)[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)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)

PHPackages © 2026

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