首页 > 其他分享 >DER编码

DER编码

时间:2023-05-01 16:56:16浏览次数:35  
标签:编码 13 06 03 55 DER 30

目录

一、实验要求

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

二、DER编码

0.查看CN、姓名、学号的16进制ASCII码

echo -n "CN" | od -tc -tx1
echo -n "xuyuan" | od -tc -tx1
echo -n "20201324" | od -tc -tx1

1.AttributeType编码

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

AttributeType OID定义 标识串 长度串 内容串
countryName 2.5.4.6 06 03 55 04 06
organizationName 2.5.4.10 06 03 55 04 0A
commonName 2.5.4.3 06 03 55 04 03

2.AttributeValue编码

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

AttributeValue 标识串 长度串 内容串
"US" 13 02 55 53
"Example rganization" 13 14 45 78 61 6D 70 6C 65 20 4F 7267 61 6E 69 7A 61 74 69 6F 6E
"Test User 1" 13 0B 54 65 73 74 20 55 73 65 72 20 31
"CN" 13 02 43 4E
"20201212" 13 08 32 30 32 30 31 33 32 34
"xuyuan" 13 0C 78 75 79 75 61 6e

3.AttributeValueAssertion编码

AttributeValueAssertion为SEQUENCE结构类型,编码规则采用结构类型定长模式。
  对于标识串,采用低标识编码方式,只需1个字节。SEQUENCE的tag为OxlO:class选择universal,则位8和位7为0,SEQUENCE为结构类型,则位6为1。因此,标识串0x30.
  对于长度串,采用短型编码方式,只需1个字节。
  对于内容串,由AttributeType和AttributeValue的DER编码值组成。
  具体编码过程如表所示。

AttributeValueAssertion 标识串 长度串 内容串
countryName="US" 30 09 06 03 55 04 06 13 02 55 53
organizationName="Example rganization" 30 1B 06 03 55 04 0A 13 14 45 78 61 6D 70 6C 65 20 4F 72 67 61 6E 69 7A 61 74 69 6F 6E
commonName="Test User 1" 30 12 06 03 55 04 03 13 0B 54 65 73 74 20 55 73 65 72 20 31
countryName="CN" 30 09 06 03 55 04 06 13 02 43 4E
organizationName="20201324" 30 1B 06 03 55 04 0A 13 08 32 30 32 30 31 33 32 34
commonName="xuyuan" 30 12 06 03 55 04 03 13 06 78 75 79 75 61 6e

4.RelativeDistinguishedName编码

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

RelativeDistinguishedName 标识串 长度串 内容串
countryName="US" 31 0B 30 09 06 03 55 04 06 13 02 55 53
organizationName="Example rganization" 31 1D 30 1B 06 03 55 04 0A 13 14 45 78 61 6D 70 6C 65 20 4F 72 67 61 6E 69 7A 61 74 69 6F 6E
commonName="Test User 1" 31 14 30 12 06 03 55 04 03 13 0B 54 65 73 74 20 55 73 65 72 20 31
countryName="CN" 31 0B 30 09 06 03 55 04 06 13 02 43 4E
organizationName="20201324" 31 11 30 0F 06 03 55 04 0A 13 08 32 30 32 30 31 33 32 34
commonName="xuyuan" 31 15 30 0D 06 03 55 04 03 13 06 78 75 79 75 61 6e

5.RDNSequence编码

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

RDNSequence 标识串 长度串 内容串
countryName="US" 30 42 31 0B 30 09  06 03 55 04 06  13 02 55 5331 1D 30 1B  06 03 55 04 0A  13 14 45 78 61 6D 70 6C 65 20 4F 72 67 61 6E 69 7A 61 74 69 6F 6E31 14 30 12  06 03 55 04 03  13 0B 54 65 73 74 20 55 73 65 72 20 31
countryName="CN" 30 37 31 0B 30 09  06 03 55 04 06  13 02 43 4E31 11 30 0F  06 03 55 04 0A  13 08 32 30 32 30 31 32 31 3231 15 30 13  06 03 55 04 03  13 0C 59 61 6e 67 20 43 68 65 6e 67 79 75

6.Name编码

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

DER编码值 ASN.1描述
30 42
 31 0B
  30 09
   06 03 55 04 06
   13 02 55 53
31 1D
 30 1B
  06 03 55 04 0A
  13 14
   45 78 61 6D 70 6C 65 20 4F 72 67
   67 61 6E 69 7A 61 74 69 6F 6E
31 14
 30 12
  06 03 55 04 03
  13 0B
   54 65 73 74 20 55 73 65 72 20 31
attributeType=country
NameattributeValue="US"

attributeType=organizationName
attributeValue="Example Organization"

attributeType=commonName
attributeValue="Test User 1"
30 37
 31 0B
  30 09
   06 03 55 04 06
   13 02 43 4E
31 11
 30 0F
  06 03 55 04 0A
  13 08
   32 30 32 30 31 33 32 34
31 0F
 30 0D
  06 03 55 04 03
  13 06
   78 75 79 75 61 6e
attributeType=countryNameattributeValue="CN"
attributeValue="CN"

attributeType=organizationName
attributeValue="20201324"

attributeType=commonName
attributeValue="xuyuan"

三、DER编码验证

0.验证

openssl asn1parse -inform der -in ./20201324.der

1.countryName="CN"

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

2.organization Name="20201324"

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

3.commonName="xuyuan"

echo -n -e "\x31\x0F\x30\x0D\x06\x03\x55\x04\x03\x13\x06\x78\x75\x79\x75\x61\x6E" >> 20201324.der

标签:编码,13,06,03,55,DER,30
From: https://www.cnblogs.com/cqszxy2020/p/17366686.html

相关文章

  • Blender-案例蛋壳小鸡
    案例:蛋壳小鸡一、蛋壳制作Shift+A新建UVSphere,Segments=16,Rings=10,选择棋盘交错式取消选区(1,1,1),G-S调整;实体化修改器,参数设置为-0.07,应用;增加倒角修改器及表面细分修改器,参数如下,K-切割(空格键确认);二、小鸡的制作眼睛:Shift+A新建UVSphere,Segments=22,Rings=1......
  • Facebook刷新开放域问答SOTA:模型训模型!Reader当Teacher!
    文|Sherry不是小哀编|小轶一部问答系统发展史就是一部人工智能发展史。早在1950年的图灵测试就提出:如果人类无法通过问答将机器和人区分开,那么这个机器就可以被认为具有智能。问答系统和人工智能有着密不可分的关系。从基于规则和结构化数据的自动问答,到基于精细设计神经网......
  • Lombok @Builder 是如何实现的
    转:lombok@Builder是如何实现的定义Builder接口,用于build对象:publicinterfaceBuilder<T>{Tbuild();}定义bean:importlombok.Getter@GetterpublicclassUserFacts{privateStringname;privateIntegerage;publicstaticUserFacts......
  • 【愚公系列】用友系列之YonBuilder低代码平台概论和基本使用
    (文章目录)一、引言1.代码平台的概念和发展历程低代码平台是一种通过可视化界面和模板化组件快速创建应用程序的平台,其发展历程主要经历了三个阶段:第一个阶段是第一代低代码平台:其主要关注业务流程管理及应用程序的速度开发,但其可扩展性和可定制性较低。第二个阶段是第二代......
  • AtCoder Regular Contest 117 D Miracle Tree
    洛谷传送门AtCoder传送门第一步就没想到可以考虑化简限制。设所有点按\(E_i\)从小到大排序后顺序是\(p_1,p_2,...,p_n\)。发现只需满足\(E_{p_{i+1}}-E_{p_i}\ge\operatorname{dis}(p_i,p_{i+1})\)。证明是对于任意\(i<j<k\),若\(p_i,p_j\)和\(p_j,p_k\)均满......
  • 如何卸载,禁用和删除Windows Defender
    彻底卸载:把如下代码复制到文本中,后缀命名为cmd,右键,使用管理员方式打开,否则会报错需要下载install_wim_tweak.exe这个软件,后面的压缩包有。cd/d"%~dp0"echoUninstalling...CLSinstall_wim_tweak.exe/o/linstall_wim_tweak.exe/o/c"Windows-Defender"/rinstall......
  • AtCoder Beginner Contest 231
    A-WaterPressure#include<bits/stdc++.h>usingnamespacestd;intmain(){ intn; cin>>n; printf("%.6lf\n",n/100.0);return0;}B-Election#include<bits/stdc++.h>usingnamespacestd;intmain(){ ios:......
  • Belender-案例一
    基础案例1:三通管制作新建柱体,更改表面细分为8,正8边形经过表面细分(视图层级3)后可以变成正圆;如下案例:初始细分8段,S——>Z,沿Z轴方向缩放,Ctrl+R环切添加细分,K切割,Shift+Alt+点选环选,E——>X——>0,沿着X轴挤压;案例2:擀面杖的制作(对称修改器)新建圆环,更改表面细分为8,按照擀面杖图......
  • CS144 计算机网络 Lab3:TCP Sender
    前言在Lab2中我们实现了TCPReceiver,负责在收到报文段之后将数据写入重组器中,并回复给发送方确认应答号。在Lab3中,我们将实现TCP连接的另一个端点——发送方,负责读取ByteStream(由发送方上层应用程序创建并写入数据),并将字节流转换为报文段发送给接收方。代码实现TCPSe......
  • PackagesNotFoundError - torchnet
    报错:PackagesNotFoundError:Thefollowingpackagesarenotavailablefromcurrentchannels:-torchnet解决办法:不用去anacconda里下载condainstallmeter改成pipinstallmeter卡了一个晚上的解决办法,简单除暴......