{"id":36574925,"url":"https://github.com/sop/asn1","last_synced_at":"2026-01-12T07:28:57.260Z","repository":{"id":42136276,"uuid":"56075924","full_name":"sop/asn1","owner":"sop","description":"A PHP library for ASN.1 DER encoding and decoding.","archived":false,"fork":false,"pushed_at":"2025-01-08T14:08:11.000Z","size":523,"stargazers_count":55,"open_issues_count":4,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-01-08T14:59:28.567Z","etag":null,"topics":["asn","asn1","decoding","der","encoding","parser","x690"],"latest_commit_sha":null,"homepage":"https://sop.github.io/asn1/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sop.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-12T15:36:42.000Z","updated_at":"2025-01-08T13:57:39.000Z","dependencies_parsed_at":"2022-08-24T14:00:27.655Z","dependency_job_id":null,"html_url":"https://github.com/sop/asn1","commit_stats":null,"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/sop/asn1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sop%2Fasn1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sop%2Fasn1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sop%2Fasn1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sop%2Fasn1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sop","download_url":"https://codeload.github.com/sop/asn1/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sop%2Fasn1/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28336519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asn","asn1","decoding","der","encoding","parser","x690"],"created_at":"2026-01-12T07:28:52.796Z","updated_at":"2026-01-12T07:28:57.250Z","avatar_url":"https://github.com/sop.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [ASN.1](https://sop.github.io/asn1/)\n\n[![Build Status](https://travis-ci.org/sop/asn1.svg?branch=master)](https://travis-ci.org/sop/asn1)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sop/asn1/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sop/asn1/?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/sop/asn1/badge.svg?branch=master)](https://coveralls.io/github/sop/asn1?branch=master)\n[![License](https://poser.pugx.org/sop/asn1/license)](https://github.com/sop/asn1/blob/master/LICENSE)\n\nA PHP library for X.690 Abstract Syntax Notation One (ASN.1)\nDistinguished Encoding Rules (DER) encoding and decoding.\n\n## Requirements\n\n- PHP \u003e=7.2\n- gmp\n- mbstring\n\n## Installation\n\nThis library is available on\n[Packagist](https://packagist.org/packages/sop/asn1).\n\n```sh\ncomposer require sop/asn1\n```\n\n## Usage\n\nThe general idea is that each ASN.1 type has its corresponding PHP class,\nthat knows the details of encoding and decoding the specific type.\n\nTo decode DER data, use `fromDER` static method of the expected type.\nTo encode object to DER, use `toDER` instance method.\n\nMany methods return an `UnspecifiedType` object, that works as an intermediate\nwrapper with accessor methods ensuring type safety.\n\nAll objects are immutable and method chaining is promoted for the fluency\nof the API. Exception shall be thrown on errors.\n\n## [Code Examples](https://github.com/sop/asn1/tree/master/examples)\n\nHere are some simple usage examples. Namespaces are omitted for brevity.\n\n### [Encode](https://github.com/sop/asn1/blob/master/examples/encode.php)\n\nEncode a sequence containing a UTF-8 string, an integer\nand an explicitly tagged object identifier, conforming to the following\nASN.1 specification:\n\n```asn.1\nExample ::= SEQUENCE {\n    greeting    UTF8String,\n    answer      INTEGER,\n    type    [1] EXPLICIT OBJECT IDENTIFIER\n}\n```\n\n```php\n$seq = new Sequence(\n    new UTF8String('Hello'),\n    new Integer(42),\n    new ExplicitlyTaggedType(\n        1, new ObjectIdentifier('1.3.6.1.3'))\n);\n$der = $seq-\u003etoDER();\n```\n\n### [Decode](https://github.com/sop/asn1/blob/master/examples/decode.php)\n\nDecode DER encoding from above.\n\n```php\n$seq = UnspecifiedType::fromDER($der)-\u003easSequence();\n$greeting = $seq-\u003eat(0)-\u003easUTF8String()-\u003estring();\n$answer = $seq-\u003eat(1)-\u003easInteger()-\u003eintNumber();\n$type = $seq-\u003eat(2)-\u003easTagged()-\u003easExplicit()-\u003easObjectIdentifier()-\u003eoid();\n```\n\n### Real-World Examples\n\nSee the following for more practical real-world usage examples.\n\n- EC Private Key\n  - [Decode](https://github.com/sop/crypto-types/blob/a27fa76d5f5e8c4596cb65a7be9d02a08421ba1e/lib/CryptoTypes/Asymmetric/EC/ECPrivateKey.php#L72)\n  - [Encode](https://github.com/sop/crypto-types/blob/a27fa76d5f5e8c4596cb65a7be9d02a08421ba1e/lib/CryptoTypes/Asymmetric/EC/ECPrivateKey.php#L206)\n- X.501 Attribute\n  - [Decode](https://github.com/sop/x501/blob/c6bdb04673d5c04b9d49f83020e75b8ba7a20064/lib/X501/ASN1/Attribute.php#L55)\n  - [Encode](https://github.com/sop/x501/blob/c6bdb04673d5c04b9d49f83020e75b8ba7a20064/lib/X501/ASN1/Attribute.php#L114)\n- X.509 Certificate (`TBSCertificate` sequence)\n  - [Decode](https://github.com/sop/x509/blob/f762c743b6930af4f45ef857ccc9f6199980a92e/lib/X509/Certificate/TBSCertificate.php#L130)\n  - [Encode](https://github.com/sop/x509/blob/f762c743b6930af4f45ef857ccc9f6199980a92e/lib/X509/Certificate/TBSCertificate.php#L576)\n\n## ASN.1 References\n\n- [ITU-T X.690 07/2002](https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf)\n- [ITU-T X.690 08/2015](https://www.itu.int/rec/T-REC-X.690-201508-I/en)\n- Hosted by [OSS Nokalva](http://www.oss.com/asn1/resources/books-whitepapers-pubs/asn1-books.html)\n  - [ASN.1 — Communication Between Heterogeneous Systems by Olivier Dubuisson](http://www.oss.com/asn1/resources/books-whitepapers-pubs/dubuisson-asn1-book.PDF)\n  - [ASN.1 Complete by Professor John Larmouth](http://www.oss.com/asn1/resources/books-whitepapers-pubs/larmouth-asn1-book.pdf)\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsop%2Fasn1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsop%2Fasn1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsop%2Fasn1/lists"}