文章目录
完成下面任务(9分)
1. 在 Ubuntu 或 openEuler 中完成任务(推荐openEuler)
2. 使用 GmSSL 命令对“你的8 位学号+姓名的首字母”进行数字签名,并参考附件 GMT0009 分解得到签名值,提交签名值结果。(4 分)
举例
学号姓名
“20221417wzy”
字符对应ascii码(16进制)是
32/30/32/32/31/34/31/37/77/7A/79
32 30 32 32 31 34 31 37 77 7a 79
“20221417wzy”是一个字节串
由于gmssl不支持直接使用asn1parse 命令来生成 ASN.1 编码的 DER 文件
所以这里采用openssl替代
//查看"20221417wzy"的ascii码
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# echo -n "20221417wzy" |od -tc -tx1
0000000 2 0 2 2 1 4 1 7 w z y
32 30 32 32 31 34 31 37 77 7a 79
0000013
//将字符串写入 data.txt
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# echo -n "20221417wzy" > data.txt
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# openssl asn1parse -genstr 'OCTETSTRING:20221417wzy' -out data.der
0:d=0 hl=2 l= 11 prim: OCTET STRING :20221417wzy
//查看生成的 DER 文件内容:
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# xxd data.der
00000000: 040b 3230 3232 3134 3137 777a 79 ..20221417wzy
对der文件进行签名验签
gmssl sm2keygen -pass 1417 -out sm2.pem -pubout sm2pub.pem
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# gmssl sm2sign -in data.der -key sm2.pem -pass 1417 -out sm2.sig -id 1234567812345678
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# gmssl sm2verify -in data.der -pubkey sm2pub.pem -sig sm2.sig -id 1234567812345678
verify : success
3. 使用 GmSSL 命令对“你的8 位学号+姓名的首字母”进行加密 ,并参考附件 GMT0009 分解得到密文数据,提交密文值。(5 分)
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# gmssl sm2encrypt -pubkey sm2pub.pem -in data.der -out sm2_encrypted.der
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# ls
data.der data.txt signature.bin sm2.pem sm2.sig sm2_encrypted.der sm2pub.pem
//查看加密文件的内容:
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# od -tx1 sm2_encrypted.der
0000000 30 77 02 21 00 e2 6f 9f 53 0b 81 af d7 76 b6 8e
0000020 8e 48 76 74 48 dd 04 e5 fd 3d 52 de 84 ac f9 2a
0000040 65 26 5d 90 9d 02 21 00 c2 ab 0b 8e cf dc 7c c9
0000060 9e 26 0c 8b e1 eb c9 46 3b 77 27 75 87 9f 09 88
0000100 67 9d 09 0b c9 12 40 05 04 20 c4 44 8c cd 42 59
0000120 9a dc 42 40 e9 cc 58 9a d1 c5 3a 0d 6a 0e 66 b5
0000140 72 a1 ee 1d 06 a9 ed bd 57 52 04 0d 23 20 c0 63
0000160 53 00 bd d4 21 66 da f5 29
0000171
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# gmssl sm2decrypt -key sm2.pem -pass 1417 -in
sm2_encrypted.der -out sm2_decrypted.der
//查看解密文件的内容
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# od -tx1 sm2_decrypted.der
0000000 04 0b 32 30 32 32 31 34 31 37 77 7a 79
0000015
git
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# git init
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /root/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2/.git/
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# git add .
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# git commit -m "提交签名值提交密文值“
> ^C
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# git commit -m "提交签名值提交密文值"
[master (root-commit) 4084437] 提交签名值提交密文值
8 files changed, 15 insertions(+)
create mode 100644 data.der
create mode 100644 data.txt
create mode 100644 signature.bin
create mode 100644 sm2.pem
create mode 100644 sm2.sig
create mode 100644 sm2_decrypted.der
create mode 100644 sm2_encrypted.der
create mode 100644 sm2pub.pem
root@LAPTOP-PRC71A0C:~/bestidiocs2024/ch03/sm2/sm2gmssl/test1/test2# git log
commit 40844377a89c90a18ba94c4bec9465e04de3bd65 (HEAD -> master)
Author: 魏正一 <11565599+wei-zhengyi@user.noreply.gitee.com>
Date: Tue Dec 10 11:47:17 2024 +0800
提交签名值提交密文值
提交要求 (1’)
- 记录实践过程和 AI 问答过程,尽量不要截图,给出文本内容
- (选做)推荐所有作业托管到 gitee或 github 上
- (必做)提交作业 markdown文档,命名为“学号-姓名-作业题目.md”
- (必做)提交作业 markdown文档转成的 PDF 文件,命名为“学号-姓名-作业题目.pdf”