2017 © Pedro Peláez
 

library phpasn1

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

image

fgrosse/phpasn1

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

  • Saturday, March 31, 2018
  • by FGrosse
  • Repository
  • 6 Watchers
  • 60 Stars
  • 638,564 Installations
  • PHP
  • 12 Dependents
  • 0 Suggesters
  • 18 Forks
  • 5 Open issues
  • 22 Versions
  • 19 % Grown

The README.md

PHPASN1

Latest Stable Version Total Downloads License, (*1)


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., (*2)

However, you are advised to migrate to alternative packages to ensure that your applications remain functional also with newer PHP versions., (*3)

Another option is to fork this repository or use [one of the existing forks][14]., (*4)

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


A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules. This encoding is very frequently used in X.509 PKI environments or the communication between heterogeneous computer systems., (*6)

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 binary data into separate PHP objects that can be manipulated by the user and reencoded afterwards., (*7)

The changelog can now be found at CHANGELOG.md., (*8)

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][13]., (*9)

For the loading of object identifier names directly from the web curl is used., (*10)

Installation

The preferred way to install this library is to rely on Composer:, (*11)

$ composer require fgrosse/phpasn1

Usage

Encoding ASN.1 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, (*12)

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 BER encoded binary data is just as easy as encoding it:, (*13)

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:, (*14)

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., (*15)

All constructed classes (i.e. Sequence and Set) can be navigated by array access or using an iterator. You can find examples here, here and here., (*16)

Give me more examples!

To see some example usage of the API classes or some generated output check out the examples., (*17)

How do I contribute?

This project is no longer maintained and thus does not accept any new contributions., (*18)

Thanks

To all contributors so far!, (*19)

License

This library is distributed under the MIT License., (*20)

The Versions

31/03 2018

dev-master

9999999-dev https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

31/03 2018

2.1.0

2.1.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

17/12 2017

2.0.1

2.0.1.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=7.0.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

17/12 2017

dev-version-1-5

dev-version-1-5 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

17/12 2017

1.5.3

1.5.3.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

17/09 2017

2.0.0

2.0.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=7.0.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

06/08 2017

dev-rename-object-class

dev-rename-object-class https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=7.0.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

05/03 2017

dev-mbstring-support

dev-mbstring-support https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

29/10 2016

1.5.2

1.5.2.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

02/10 2015

1.5.1

1.5.1.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

x509 x.509 asn1 asn.1 binary encoding decoding der x690 x.690 ber

30/09 2015

dev-compat/php5-5

dev-compat/php5-5 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.5.0

 

The Development Requires

30/09 2015

1.5.0

1.5.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

29/09 2015

1.4.2

1.4.2.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

15/09 2015

1.4.1

1.4.1.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

17/08 2015

1.4.0

1.4.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.6.0

 

The Development Requires

15/07 2015

1.3.2

1.3.2.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.3.0

 

The Development Requires

28/04 2015

1.3.1

1.3.1.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.3.0

 

The Development Requires

28/04 2015

1.3.0

1.3.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • ext-gmp *
  • php >=5.3.0

 

The Development Requires

05/04 2015

1.2.0

1.2.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

14/02 2015

1.1.0

1.1.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

GPLv3

The Requires

  • php >=5.3.0

 

The Development Requires

03/02 2015

1.0.0

1.0.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

GPLv3

The Requires

  • php >=5.3.0

 

The Development Requires

03/02 2015

0.9.0

0.9.0.0 https://github.com/FGrosse/PHPASN1

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

  Sources   Download

GPLv3

The Requires

  • php >=5.3.0

 

The Development Requires