在Linux上使用OpenSSL进行数字签名,通常涉及以下步骤:
生成密钥对:
openssl genpkey
命令生成私钥。openssl rsa
或openssl ecparam
等命令从私钥派生公钥。准备要签名的数据:
data.txt
。创建数字签名:
验证数字签名:
以下是具体的命令示例:
# 生成RSA私钥
openssl genpkey -algorithm RSA -out rsa_private_key.pem -aes256
# 从私钥派生公钥
openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
假设你要签名的数据保存在data.txt
文件中。
# 使用SHA-256哈希算法对数据进行签名
openssl dgst -sha256 -sign rsa_private_key.pem -out signature.bin data.txt
# 使用公钥验证签名
openssl dgst -sha256 -verify rsa_public_key.pem -signature signature.bin data.txt
如果签名有效,你会看到输出类似于:
Verified OK
如果签名无效,你会看到输出类似于:
Verification Failure
通过以上步骤,你可以在Linux上使用OpenSSL进行数字签名和验证。