目录
创建一个内容为GuetPython的明文文件hello.txt
使用genrsa产生1024bit的明文rsa私钥privacy.pem,即没有加密过的私钥
使用私钥privacy.pem签名hello.txt为hello.sig
使用公钥文件public.pem验证签名hello.sig为hello.ver
测试文件会使用cat命令输出hello.ver的内容检查验证签名是否正确。
前言
附上openssl的文档:openssl文档
1.编程要求
-
创建一个内容为GuetPython的明文文件hello.txt
-
使用genrsa产生1024bit的明文rsa私钥privacy.pem,即没有加密过的私钥
-
使用rsa输出公钥文件public.pem
-
使用私钥privacy.pem签名hello.txt为hello.sig
-
使用公钥文件public.pem验证签名hello.sig为hello.ver
-
测试文件会使用cat命令输出hello.ver的内容检查验证签名是否正确。
2.完整代码
代码如下(示例):
echo GuetPython >hello.txt
openssl genrsa -out privacy.pem 1024
openssl rsa -in privacy.pem -pubout -out public.pem
openssl rsautl -sign -inkey privacy.pem -in hello.txt -out hello.sig
openssl rsautl -verify -inkey privacy.pem -in hello.sig > hello.ver
这里按照要求应该是使用公钥去验证签名,可是文档用的却是私钥去验证签名。

这里我不是很懂了。然后我用公钥去验证签名就打印不出来内容。(有知道原因的嘛)
猜测可能是因为私钥是成对生成的。
使用命令查看一下私钥和公钥:
echo GuetPython >hello.txt
openssl genrsa -out privacy.pem 1024
openssl rsa -in privacy.pem -pubout -out public.pem
openssl rsa -in privacy.pem -text -noout
openssl rsa -pubin -in public.pem -text -noout