### Install PHPASN1 using Composer Source: https://github.com/maajiko/epay/blob/main/includes/vendor/fgrosse/phpasn1/README.md Use Composer to install the PHPASN1 library. This is the recommended installation method. ```bash $ composer require fgrosse/phpasn1 ``` -------------------------------- ### Parsing Binary Data with a Template Source: https://github.com/maajiko/epay/blob/main/includes/vendor/fgrosse/phpasn1/README.md Use TemplateParser to parse binary data according to a predefined template structure. This method throws an exception if the data does not match the template. ```php 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); ``` -------------------------------- ### Encoding ASN.1 Structures Source: https://github.com/maajiko/epay/blob/main/includes/vendor/fgrosse/phpasn1/README.md Create and encode various ASN.1 universal types like Integer, Boolean, IA5String, ObjectIdentifier, Sequence, and Set. The data is encoded using DER encoding. ```php 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 BER Encoded Binary Data Source: https://github.com/maajiko/epay/blob/main/includes/vendor/fgrosse/phpasn1/README.md Decode BER encoded binary data into an ASNObject. Ensure the binary data is correctly decoded from its base64 representation before parsing. ```php use FG\ASN1\ASNObject; $base64String = ... $binaryData = base64_decode($base64String); $asnObject = ASNObject::fromBinary($binaryData); // do stuff ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.