SIMPLE-TLV和BER-TLV [英] SIMPLE-TLV vs BER-TLV

查看:386
本文介绍了SIMPLE-TLV和BER-TLV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中发现他们指的是 SIMPLE-TLV BER-TLV .我查看了大多数EMV和GP文档,但他们没有提到它们的不同之处.

I have found in docs they are referring to SIMPLE-TLV and BER-TLV . I was look into most of the EMV and GP docs but they have not mentioned the different.

有人可以帮助我理解两者的区别吗?

Could anyone help me to understand the difference of two ?

推荐答案

ISO/IEC 7816-4中用于智能卡的数据字段

BER编码

这是ISO使用的更常见的 BER编码的规范/IEC 7816-4:

Data fields in ISO/IEC 7816-4 for smart cards

BER encoding

This is the specification of the more common BER encoding used by ISO/IEC 7816-4:

每个BER-TLV数据对象应包含2个或3个连续字段 (请参阅ISO/IEC 8825和附件D).

Each BER-TLV data object shall consists of 2 or 3 consecutive fields (see ISO/IEC 8825 and annex D).

标签字段T由一个或多个连续字节组成.它编码 一个类,一个类型和一个数字.长度字段包含一个或多个 连续字节.它编码一个整数L.如果L不为null,则 值字段V由L个连续字节组成.如果L为空,则 数据对象为空:没有值字段.

The tag field T consists of one or more consecutive bytes. It encodes a class, a type and a number. The length field consists of one or more consecutive bytes. It encodes an integer L. If L is not null, then the value field V consists of L consecutive bytes. If L is null, then the data object is empty: there is no value field.

请注意,在当前标准中,ISO/IEC 7816仅允许使用最多5个长度的字节(指定大小最大为2 ^ 32-1字节).也不支持不定长度编码.这些限制特定于智能卡.请注意,在更高版本的ISO/IEC 7816-4中引入了4和5字节长度的编码.较早的卡/读卡应用程序可能仅支持3个长度的字节(即,值大小最大为64KiB字节,而不是4GiB).

Note that ISO/IEC 7816 only allows the use of up to 5 length bytes (specifying a size up to 2^32 - 1 bytes) in the current standard. Indefinite length encoding is not supported either. These limitations are specific to smart cards. Note that 4 and 5 byte length encodings were introduced in a later version of ISO/IEC 7816-4; earlier cards / card reading applications may only support 3 length bytes (i.e. a value size up to 64KiB bytes, instead of 4GiB).

BER TLV规范更加扩展(这就是为什么SIMPLE-TLV被称为简单")的原因.由于互联网上有大量可用信息,因此我不会过多地讨论细节.仅举几个区别,这些标签具有语法含义,可能包含多个字节,并且长度编码相当复杂.

The BER TLV specification is much more expansive (which is why SIMPLE-TLV is called "simple"). I won't go into the details too much as there is plenty of information available on the internet. To name just a few differences, the tags have syntactical meaning and may consist of multiple bytes and the length encoding is rather complex.

通常,仅应将BER用作ASN.1结构的编码,并使用ASN.1语法定义该结构.但是ISO 7816-4搞砸了,只能直接指定BER标签字节.

Normally BER should only be used as an encoding of ASN.1 structures, with the ASN.1 syntax defining the structure. ISO 7816-4 however messes this up and only specifies the BER tag bytes directly.

请注意,有时会指定DER而不是BER.在这种情况下,您应该仅使用最小字节数作为长度字段的大小-例如在以下示例中,单个长度字节的值为05. BER编码的ISO/IEC规范基本上是美国特定的X.690标准的副本,也反映在国际标准ISO/IEC 8825-1(均为付费软件)中.

Note that sometimes DER is specified instead of BER. In that case you should only use the minimum number of bytes for the size of the length field - e.g. a single length byte with value 05 in the samples below. The ISO/IEC specification of BER encoding is basically a copy of the US specific X.690 standard, also reflected in the international standard ISO/IEC 8825-1 (both payware).

ISO/IEC 7816-4中的BER规范后面是SIMPLE-TLV规范. SIMPLE-TLV特定于ISO 7816-4.

The BER specification in ISO/IEC 7816-4 is followed by the SIMPLE-TLV specification. SIMPLE-TLV is specific to ISO 7816-4.

每个SIMPLE-TLV数据对象应包含2个或3个连续的 字段.

Each SIMPLE-TLV data object shall consist of 2 or 3 consecutive fields.

标记字段T由一个单字节组成,仅对来自 1到254(例如记录标识符).它没有分类也没有编码 建筑类型.长度字段包含1或3个连续的 个字节.如果length字段的前导字节在以下范围内 从"00"到"FE",则长度字段由单字节编码组成 一个从0到254的整数L.如果前导字节等于 'FF',然后长度字段在随后的两个字节上继续 编码从0到65535的整数L.如果L in 不是 如果为null,则值字段V由连续的字节组成.如果L是 null,则数据对象为空:没有值字段.

The tag field T consists of a single byte encoding only a number from 1 to 254 (e.g. a record identifier). It codes no class and no construction-type. The length field consists of 1 or 3 consecutive bytes. If the leading byte of the length field is in the range from '00' to 'FE', then the length field consists of a single byte encoding an integer L valued from 0 to 254. If the leading byte is equal to 'FF', then the length field continues on the two subsequent bytes which encode an integer L with a value from 0 to 65535. If L in not null, then the value field V consists of consecutive bytes. If L is null, then the data object is empty: there is no value field.

请注意,标准忘记直接指定字节序.但是,您可以在ISO/IEC 7816-4中采用大端编码.

Note that the standard forgets to specify the endianness directly. You can however assume big endian encoding within ISO/IEC 7816-4.

除为BER定义标签号31的样本外,以下所有示例均用于传达相同的标签号(定义字段)和值.

The following samples are all used to convey the same tag number (which defines the field) and value, except one that defines tag number 31 for BER.

SIMPLE-TLV示例

Sample SIMPLE-TLV

0F 05 48656C6C6F                 // tag number 15, length 5 then the value
0F FF0005 48656C6C6F             // tag number 15, length 5 (two bytes), then the value

BER-TLV示例:

Sample BER-TLV:

4F 05 48656C6C6F                 // *application specific*, primitive encoding of tag number 15, length 5 then the value
4F 8105 48656C6C6F               // the same, using two bytes to encode the length
4F 820005 48656C6C6F             // the same, using three bytes to encode the length
4F 83000005 48656C6C6F           // the same, using four bytes to encode the length
4F 8400000005 48656C6C6F         // the same , using five bytes to encode the length
5F0F 05 48656C6C6F               // **invalid** encoding of the same, with two bytes for the tag, specifiying a tag number 15 which is smaller than 31
5F1F 05 48656C6C6F               // application specific, primitive encoding of **tag number 31**

在具有两个字节标记编码的最后一个示例中,第一个字节为40十六进制,其中最左边的前3个位010指定应用程序特定的编码,在其上加上魔术值1F(31)表示将跟随另一个字节加上实际的标签号,再次为1F,因此值为31.

In the last example with the two byte tag encoding, the first byte is 40 hex, where the first 3 leftmost bits 010 specify application specific encoding, adding the magic value 1F (31) to it to indicate that another byte will follow with the actual tag number, again 1F, so value 31.

应注意以下差异:

  • SIMPLE-TLV是一种不同的标记和长度编码方法(尽管编码可能看起来类似,例如,当使用单个字节指示长度部分时)
  • SIMPLE-TLV不包含有关字段类别的信息,例如如果它是为ASN.1定义的(因为它未链接到ASN.1)
  • SIMPLE-TLV是原始的还是构造的(原始直接指定一个值,构造的意思是嵌套的TLV结构)不包含信息
  • SIMPLE-TLV对标签号(介于1到254之间(包括1和254之间)和长度(最多65535))有限制

这篇关于SIMPLE-TLV和BER-TLV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆