目录
创建一个内容为GuetPython的明文文件hello.txt
使用genrsa产生1024bit的明文rsa私钥privacy.pem,即没有加密过的私钥
使用dgst摘要算法sha256和私钥privacy.pem实现签名hello.txt为hello.sha256
使用dgst摘要算法sha256和公钥文件public.pem验证签名hello.sha256,并把验证结果Verified OK输出到result.txt文件
测试文件会使用cat命令输出result.txt的内容检查验证签名是否正确。
前言:
附上openssl的文档:openssl文档
一、编程要求
-
创建一个内容为GuetPython的明文文件hello.txt
-
使用genrsa产生1024bit的明文rsa私钥privacy.pem,即没有加密过的私钥
-
使用rsa输出公钥文件public.pem
-
使用dgst摘要算法sha256和私钥privacy.pem实现签名hello.txt为hello.sha256
-
使用dgst摘要算法sha256和公钥文件public.pem验证签名hello.sha256,并把验证结果Verified OK输出到result.txt文件
-
测试文件会使用cat命令输出result.txt的内容检查验证签名是否正确。
二、完整代码
echo GuetPython >hello.txt
openssl genrsa -out privacy.pem 1024
openssl rsa -in privacy.pem -pubout -out public.pem
openssl dgst -sha256 -sign privacy.pem -out hello.sha256 hello.txt
openssl dgst -verify public.pem -sha256 -signature hello.sha256 hello.txt >result.txt