DER编码

任务详情

  1. 参考附件中图书p120 中7.1的实验指导,完成DER编码
  2. Name实例中,countryName改为“CN”,organization Name-"你的学号" commoaName="你的姓名拼音"
  3. 用echo -n -e "编码" > 你的学号.der中,用OpenSSL asn1parse 分析编码的正确性
  4. 提交编码过程文档(推荐markdown格式)

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所示。

2. AttributeValue编码

AttributeValue为 PrintableString 基本类型,编码规则采用基本类型定长模式。
对于标识串,采用低标识编码方式,只需1个字节。PrintableString 的tag 为0x13;class选择universal,则位8和位7为0,OBJECT IDENTIFIER为基本类型,则位6为0。因此,标识串=Ox13。
对于长度串,采用短型编码方式,只需1个字节。对于内容串,由其ASCII码组成。
具体编码过程如表7-2所示。

Attributevalue 标识串 长度串 内容串
CN 13 02 43 4E
20201224 13 08 32 30 32 30 31 32 32 34
Wu Zhuohang 13 0B 57 75 20 5a 68 75 6f 68 61 6e 67

3. AttributeValueAssertion编码

AttributeValueAssertion为 SEQUENCE结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SEQUENCE的 tag 为0x10; class

选择universal,则位8和位7为0,SEQUENCE为结构类型,则位6为1。因此,标识串=Ox30。
对于长度串,采用短型编码方式,只需1个字节。
对于内容串,由AttributeType和 AttributeValue的 DER编码值组成。具体编码过程如表7-3所示。

AttributeValueAssertion 标识串 长度串 内容串
countryName="CN" 30 09 06 03 55 04 06 13 02 43 4E
organizationName="20201224” 30 0F 06 03 55 04 0A 13 08 32 30 31 38 31 32 31 37
commonName ="Wu Zhuohang" 30 13 06 03 55 04 03 13 0B 57 75 20 5a 68 75 6f 68 61 6e 67

4. RelativeDistinguishedName编码

RelativeDistinguishedName为SET OF结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SET OF的tag 为0x11; class选择universal,则位8和位7为0,SET OF 为结构类型,则位6为1。因此,标识串=Ox31。
对于长度串,采用短型编码方式,只需1个字节。
对于内容串,由Attribute ValueAssertion的 DER编码值组成。具体编码过程如表7-4所示。

RelativeDistinguishedName 标识串 长度串 内容串
countryName="CN" 31 0B 30 09 06 03 55 04 06 13 02 43 4E
organizationName="20201224” 31 11 30 0F 06 03 55 04 0A 13 08 32 30 31 38 31 32 31 37
commonName ="Wu Zhuohang" 31 15 30 13 06 03 55 04 03 13 0B 57 75 20 5a 68 75 6f 68 61 6e 67

5. RDNSequence编码

RDNSequence为SEQUENCE-OF结构类型,编码规则采用结构类型定长模式。对于标识串,采用低标识编码方式,只需1个字节。SEQUENCE OF的 tag 为0x10;class选择universal,则位8和位7为0,SEQUENCE OF为结构类型,则位6为1。因此,标识串=Ox30。
对于长度串,采用短型编码方式,只需1个字节。
对于内容串,由3个RelativeDistinguishedName的 DER编码值组成。具体编码过程如表7-5所示。

RDNSequence 标识串 长度串 内容串
countryName="CN" 30 37 31 0B 30 09 06 03 55 04 06 13 02 43 4E 30 0F 06 03 55 04 0A 13 08 32 30 31 38 31 32 31 37 30 13 06 03 55 04 03 13 0B 57 75 20 5a 68 75 6f 68 61 6e 67

6.Name编码

Name为CHOICE类型,其DER编码值与RDNSequence相同。用户Test User 1最终DER编码值如表7-6所示。

DER编码值 ASN.1描述
31 0B 30 09 06 03 55 04 06 13 02 43 4E 30 0F 06 03 55 04 0A 13 08 32 30 31 38 31 32 31 37 30 13 06 03 55 04 03 13 0B 57 75 20 5a 68 75 6f 68 61 6e 67 attributeType = countryName; attributeValue = "CN" ;attributeType = organizationName ;attributeValue = "20201224" ;attributeType = commonName ;attribute Value = "Wu Zhuohang"

1.countryName="CN"

echo -n -e "\x31\x0B\x30\x09\x06\x03\x55\x04\x06\x13\x02\x43\x4E" > 20201224.der

2.organization Name="20201224"

echo -n -e "\x31\x11\x30\x0F\x06\x03\x55\x04\x0A\x13\x08\x32\x30\x32\x30\x31\x32\x32\x34" >> 20201224.der

3.commonName="Wu Zhuohang"

echo -n -e "\x31\x15\x30\x13\x06\x03\x55\x04\x03\x13\x0B\x57\x75\x20\x5a\x68\x75\x6f\x68\x61\x6e\x67" > 20201224.der

posted @ 2023-05-05 19:23  20201224吴卓航  阅读(88)  评论(0)    收藏  举报