Sop/ASN1 PHP Library

Sop/ASN1 PHP Library

PHP библиотека для кодирования и декодирования алгоритмов X.690 ASN.1 DER для Joomla 3 и Joomla 4


Подключение PHP библиотеки ASN1 в Joomla

Пример кода для Joomla 3 и Joomla 4.

defined('_JEXEC') or die('Restricted access');
use \Sop\ASN1\Element;
use \Sop\ASN1\Type\Constructed\Sequence;

// Для Joomla 3

JLoader::registerNamespace('Sop', JPATH_LIBRARIES);

// ИЛИ 
// для  Joomla 4
JLoader::registerNamespace('Sop', JPATH_LIBRARIES. '/Sop');

Различия в указании namespaces  в Joomla 3  и Joomla 4

В Joomla 3 следует указывать путь, после которого начинается namespace.

В Joomla 4 следует указывать путь вплоть до каталога, где начинается namespace.

ASN1 PHP Library

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


  • PHP >=7.2
  • gmp
  • mbstring


This library is available on Packagist.

composer require sop/asn1


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

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


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,


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


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

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

ASN.1 References


Тип расширения:
Версия Joomla:

Что нового

SOP/ASN1 Library v.4.1.1

Версия от 17 февраля 2022 года.

Расширения Joomla WebTolk

85 Всего расширений
11 Категорий
354 Выпущено версий
348907 Всего скачиваний
Корзина пуста