ASN1 研究1


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








      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.








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


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.


个人分类: java 安全
想对作者说点什么? 我来说一句



ASN1 研究1