DER编码

X.501 Name类型用ASN.1描述如下:
Name ::=CHOICE{ RDNSequence }
RDNSequence ::= SEQUENCE OF RelativeDistinguishedNameRelativeDistinguishedName ::= SET OF AttributeValueAssertionAttribute ValueAssertion ::= SEQUENCE{
AttributeType,
AttributeValue }
AttributeType ::= OBJECT IDENTIFIERAttribute Value ::= ANY

Name类型定义为CHOICE类型,目前只有1个选项RDNSequence。RDNSequence定义为SEQUENCEOF类型,由0个或多个RelativeDistinguishedName组成。RelativeDistinguished-Name定义为SET OF类型,由0个或多个AttributeValueAssertion组成。AttributeValueAssertion定义为SEQUENCE类型,由2个成分组成:1个为AttributeType类型和1个AttributeValue类型。AttributeType定义为OBJECT IDENTIFIER类型。AttributeValue定义为ANY类型,具体内容由AttributeType决定。
事实上,Name类型可理解为分层或树形结构,即X.500目录树结构。

2.Name实例

对于用户Test User 1,其对应的Name类型采用分层结构描述为:
(root)
countryName = "CN"
organization Name= "20201214"
commonName = "luoyunfan"

其中,每层对应一个RelativeDistinguishedName;每个RelativeDistinguishedName 由1个AttributeValueAssertion组成。等号前内容为AttributeType,等号后内容为AttributeValue。
用户Test User 1包含3个AttributeType: countryName. organizationName,commonName,其OID定义如下:

attributeType OBJECT IDENTIFIER ::= { joint-iso-ccitt(2) ds(5)4}countryName OBJECT IDENTIFIER:= { attributeType 6 }
organizationName OBJECT IDENTIFIER::= { attributeType 10 }commonName OBJECT IDENTIFIER::= { attributeType 3 }

3.DER编码过程

1. AttributeType编码
AttributeType为OBJECT IDENTIFIER基本类型,编码规则采用基本类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。OBJECT IDENTIFIER的tag 为Ox06;class选择universal,则位8和位7为0,OBJECT IDENTIFIER为基本类型,则位6为0。因此,标识串=Ox06。
对于长度串,采用短型编码方式,只需1个字节。
对于内容串,由3个字节组成。2.5.4.6编码为550406,2.5.4.10编码为5504 0A,2.5.4.3编码为55 04 03。
具体编码过程如表7-1所示。

 

posted @ 2023-05-07 14:23  20201214罗云帆  阅读(28)  评论(0编辑  收藏  举报