ASN1 研究1

原创 2012年04月08日 16:14:03

一、ASN1的类型

         分为:简单类型(simple types),字符类型(String types),structured types(结构类型).

      字符类型又分为两类:一类是处理原始二进制字节,另一类是代表特定字符的编码

    结构类型由SEQUENCE和SET组成。

 

    简单类型:BOOLEAN、ENUMERATEDINTEGER、NULL、OBJECT IDENTIFIER、UTCTime、GeneralizedTime

                      boolean用来编码true或者false

                     null代表的是空值,而不是空,不存在

                     UTCTIme只有两位数的年份,GeneralizedTime是四位数的年份。它们都把时间转换成ASCII编码字符,GeneralizedTime可以精确的秒,

      Bit String Type(位字符串类型):         BIT STRING、OCTET STRING

                   BIT STRING:可以存储任意长度的任意字节,一个bit String由两部分组成,一部分是包含实际字符和0到7个补位的字符,以保证该部分字符长度是8的倍数。另一部  分 是记录补位的个数。一个bit String 的长度可以为0.

           OCTET STRING:可以存储8位字节的字符,与java byte数组匹配

     

 

 

BOOLEAN encodes a true or false value.

ENUMERATED is a special case of INTEGER that can be used to represent signed integers of any magnitude. Note that I saidsignedINTEGER values are encoded as two's-complement numbers, high byte first in "big endian" format.

You can think of NULL in a similar way to the Java null, although there is a slight twist, as it is ASN.1's way of distinguishing a value set to nothing, rather than absent, which you will see later is also a possibility.

You have already learned what object identifiers are in the section on basic ASN.1 syntax. Not surprisingly,OBJECT IDENTIFIER is the type they are given.

UTCTime and GeneralizedTime are two that deserve some special attention; both are used to define a "Coordinated Universal Time," butUTCTime has only a two-digit year.GeneralizedTime has a four-digit year. Both objects represent time as strings of ASCII, with major differences being thatGeneralizedTime has a four-digit year and can represent seconds to an arbitrary precision, whereasUTCTime has a two-digit year and cannot go any lower than seconds in its resolution. Although it should be obvious how aGeneralizedTime is used, a question remains: How do you deal with the two-digit year inUTCTime?

One interpretation of UTCTime is that the two-digit year is interpreted as spanning the century starting from 1950 to 2049, but others are also used. AUTCTime can also be interpreted as going from 1900 to 1999, or as being on a sliding window, as in if it's 2005, the digits 55 to 99 are interpreted as indicating 1955 to 1999, and 0 to 55 is interpreted as meaning 2000 to 2055. How you work this one out depends on the standard you are working with, but you will be relieved to know that for the most part people have settled on the meaning that maps 50 to 99 as 1950 to 1999, and 00 to 49 as 2000 to 2049.

 

                  

二、类型标签

       在ASN.1中,一个类型就是一个值的集合。有些类型有有限个值,有些类型有无限个值。一个给定的的ASN。1类型的值是该类型集合里的一个元素。

      除了CHOICE和ANY类型外,每种ASN1类型都有一个标签,由一个类和一个非负的标签树组成。标签的值可以唯一区分ASN1类型。也就是说ASN1类型的名字并 

     不影响它的抽象含义,只有标签的值才有这个作用。

 

The most important of these modifiers for you is bit 6, which if set means the type is a constructed type

最重要的是第六位的编码,如果设置为1,那么表示为结构化类型,意味着后面的字节流由其它ans1对象组成,以便组装成对象解析。

Therefore, although the tag value for SEQUENCE is 0×10 and SET is 0×11, the encoded values you will encounter will be 0×30 to indicate aSEQUENCE follows and 0×31 to indicate a SET, because both these types are composed of one or more other ASN.1 objects.

因此,虽然SEQUENCE是0x10,SET是0x11,编码值将会是0x30或者0x31,因为这两种类型都由其他asn1对象组成

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

非对称加密算法的本质

非对称加密算法的本质就是利用了一些数学难题,比如rsa利用了大数分解的难题,dh利用了离散对数的难题,而ecc利用了椭圆曲线域上的理论,这些被成为难题,仅仅是难而已,理论上是有解并且可解的,比如大数分...
  • dog250
  • dog250
  • 2010-05-02 11:12
  • 2611

TLS1.3规范(RFC文档)

The Transport Layer Security (TLS) Protocol Version 1.3 (draft-ietf-tls-tls13-latest) TLS支持三种基本的密钥...

扫盲 HTTPS 和 SSL/TLS 协议[2]:可靠密钥交换的难点,以及身份认证的必要性

文章目录 ★先插播一个安全通告 ★方案1——单纯用“对称加密算法”的可行性 ★方案2——单纯用“非对称加密算法”的风险 ★方案2失败的根源——缺乏【可靠的】身份认证 ★身份认证的几种方式 ★如何解决 ...

asn1编码格式的解析过程

本文以x509的解析为例说明asn1的编码格式的解析逻辑。x509证书的解析实际上是asn1格式的解析,这里着重说的是asn1的ber编码的解析,总的来讲,asn1格式的解析过程有三个重要的元素,一个...
  • dog250
  • dog250
  • 2010-05-02 15:09
  • 13423

ASN1 研究4

类型规则                    For small value tags, from 0 to 3...

Openssl ASN.1 说明

openssl之ASN.1系列之1---引言和ASN.1概述 【引言】 ASN.1全称为Abstract Syntax NotationOne,是一种描述数字对象的方法和标准。openssl的...

ASN.1 berview 查看

  • 2015-02-01 14:27
  • 134KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)