0

我有一个用于编码 ASN1 的地图,就像我使用 phpseclip 进行编码一样:

IdentityIdentificationDataObjectMap = array('type' => FILE_ASN1_TYPE_SEQUENCE,
    'children' => array(
        'identityIdentificationDataObject' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
            'children' => array(
                'identityIdentificationData' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
                    'children' => array(
                        'version' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
                        'staticData' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
                            'children' => array(
                                'acceptedPolicyVersion' => array('type' => FILE_ASN1_TYPE_IA5_STRING),
                                'cardHolderID' => array('type' => FILE_ASN1_TYPE_INTEGER),
                                'deviceSerialNumber' => array('type' => FILE_ASN1_TYPE_SEQUENCE,
                                    'children' => array(
                                        'deviceType' => array('type' => FILE_ASN1_TYPE_INTEGER),
                                        'deviceUniqueID' => array('type' => FILE_ASN1_TYPE_OCTET_STRING)
                                    ),
                                ),
                                'appLabel' => array('type' => FILE_ASN1_TYPE_UTF8_STRING),
                                'requestorRole' => array('type' => FILE_ASN1_TYPE_ENUMERATED,
                                    'mapping' => array(
                                        'roleClient',
                                        'roleParticipant'
                                    ),
                                ),
                                .
                                .
                                .

当我用我的数组编码时,这个网站上的输出就像这样:https ://lapo.it/asn1js/

SEQUENCE(1 elem)
  SEQUENCE(2 elem)
    SEQUENCE(2 elem)
      IA5String 2.0
      SEQUENCE(6 elem)
        IA5String 2
        INTEGER(37 bit) 90000100526
        SEQUENCE(2 elem)
          INTEGER 3
          .
          .
          .

但是我想将 Application 7 标签添加到我的 ASN1 中,并且我想要这样的输出。

Application 7(2 elem)
  [0](2 elem)
    [0]2.0
    [1](6 elem)
      [0]2
      [1]90000100526
      [2](2 elem)
        [0](1 byte) 3
          .
          .
          .

我想知道是否可以使用 phpseclip 给 Application X 标签。我的 php 版本 5.5。就像没有任何标签的那样,只需 [0][1] 标签将我的数组编码为 ASN1。

首先有可能然后怎么办?肿瘤坏死因子。寻求答案。

4

1 回答 1

1

如果您使用最新版本的 phpseclib 1.0(截至本文为 1.0.11),应该可以。https://github.com/phpseclib/phpseclib/blob/1.0.11/tests/Unit/File/ASN1Test.php#L303提供了一个例子:

public function testApplicationTag()
{
    $map = array(
        'type'     => FILE_ASN1_TYPE_SEQUENCE,
        'children' => array(
            // technically, default implies optional, but we'll define it as being optional, none-the-less, just to
            // reenforce that fact
            'version'             => array(
                // if class isn't present it's assumed to be FILE_ASN1_CLASS_UNIVERSAL or
                // (if constant is present) FILE_ASN1_CLASS_CONTEXT_SPECIFIC
                'class'    => FILE_ASN1_CLASS_APPLICATION,
                'cast'     => 2,
                'optional' => true,
                'explicit' => true,
                'default'  => 'v1',
                'type'     => FILE_ASN1_TYPE_INTEGER,
                'mapping' => array('v1', 'v2', 'v3')
            )
        )
    );
    $data = array('version' => 'v3');
    $asn1 = new File_ASN1();
    $str = $asn1->encodeDER($data, $map);
    $decoded = $asn1->decodeBER($str);
    $arr = $asn1->asn1map($decoded[0], $map);
    $this->assertSame($data, $arr);
}
于 2018-04-15T04:48:17.610 回答