定制 sop/asn1 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sop/asn1

最新稳定版本:4.1.2

Composer 安装命令:

composer require sop/asn1

包简介

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

README 文档

README

Build Status Scrutinizer Code Quality Coverage Status License

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

Requirements

  • PHP >=7.2
  • gmp
  • mbstring

Installation

This library is available on Packagist.

composer require sop/asn1

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

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

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

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

License

This project is licensed under the MIT License.

统计信息

  • 总下载量: 1.52M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 62
  • 点击次数: 2
  • 依赖项目数: 46
  • 推荐数: 0

GitHub 信息

  • Stars: 60
  • Watchers: 6
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-12