我正在开发基于OpenSSL 0.9.8a API的应用程序,我需要使用RSA公钥pubkey
验证RSA签名(4096位RSA密钥)。
这是我的代码:
const EVP_MD* md = EVP_get_digestbyname("SHA512");
if (!md)
{
return false;
}
if(EVP_DigestInit_ex(ctx, md, NULL)<=0)
{
return false;
}
if(EVP_DigestVerifyInit( ctx, NULL, md, NULL, pubKey)<=0)
{
return false;
}
if (EVP_DigestUpdate(ctx, Msg, MsgLen) <= 0)
{
return false;
}
int res = EVP_DigestFinal_ex(ctx, MsgHash, &MsgHashLen);
问题是openssl0.9.8a中没有定义EVP_DigestVerifyInit
函数。
是否有其他方法可以在早于OpenSSL 1.0.0版本的版本中验证RSA签名?
以下是我的意见: / * Text_message保存到&#34; sample.txt&#34;文件(文字以最后一个字符结尾&#39; \ n&#39;)* /
My secret message.\n
/ *生成RSA公钥* /
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAl44E9YikPF9RzjAWxZXO
/GaJVCVdQOjp6pmSgL38WvS7glqMwQFwBzSqAiuvVkf3j9C+9Cgs2pypamfDBabC
CZX9+c4oE9zxW2wz0yT5dKL+lUuvIeKfDTMvttjHPtMn23S4ASqLZFAeJX0bCd9H
6l2/8KBjV+uinVlwvKGjXbE5ds2/8S2gei17WvdTb2ypvAUhdw7dc8IaSosG5lOa
EycLN6XKq0z8UX336PiuY0FzLa2B3FOOc6TuPpjkRuf73YKt/Xtm+78ztkfwHLUs
v+EX0TJpB8jE4DISiogNrceOPOnFipppxau2t0VjLivmYTnvSbJzIbOmutFGX8HV
17m3tUpATCdVDuMJ3ouCWOjIJSvw60gizOUHqmMBX+qG95mQ1h3QGP7SExYDKgfp
VpIEAVsnv+CvZTGOEIYcO9ROI2FM6fBgDxkHAdWFCkBVK6o5JxYmsHAXOfFVh+FD
K/pxCBuQINn5B6xanBJYmtpbtq7D0UcvVn6HP7w/9X/pvdU90+KMx1p5AZ6WFeNB
BWLp4whPnU6VEFo+UwXyrCWPIlq3vAz/TjxOXW0Plw+xtsoyw15C8+mS9/4x9XyV
O9v4vlvsRL46T/h4axVsbf2B5w4JC4VoNTuomObecQ0s3v+v54ZYJNsp/tLMa02n
+N9hImCjf+Y6HF8s6BKQ1B0CAwEAAQ==
-----END PUBLIC KEY-----
/ * base64编码的Signatue保存到&#34; PKGC_sample_singed.enc64&#34;文件* /
NIInzKblrnRZ3olbVUSJbYQhnn9VvDaadcsLNLAVRS/2rryzQr8FVo7ty4oQYqQT
KwRkwVakCxqs+Dg+wHCHQ+K6D6d43nGodC0kNgD1++vYeorUbpK7QNdMu+73g5pW
TiYCicKp6DfeYGWPLI0aYivQJqwNMxqrFd/CdNWhIap4f4fZb5WHcszqlsLCqtrr
qVLP3fXVlHzfiA6jqx2GVE5m43iXLB2H3DwXmjS8eX0veRTlcU5lOtoH/yAGRxmL
p3Mg/s3LSdiAL4Gki4nSORWVmsJ0IwtRttLAl5wYN2VAWz8n21wjCTcr9f2k7BQy
/W74zug+8rbnejFoS50YOKB27PKUTcv0Qn5tWYrk/BK4FPovXyj+tPHZ+jIvAdvX
7UbGl1fkyylb2C6DUxlPPZRxjiaoA4xKwaSFrwcMQnVFphE/LuyQ5aBQZVtAI8Sj
K4zws2BjbCUh+JWzJawCZmIt8IEq1IavW/t/YaMIqR4IMMnHghZGhN8Hm34UOIwB
uyTx1bX/AlKIs7h2ibKSL5JKunQ2IbLqvPeyhjLoFdqiv57JsIzA154xFyl1uXlj
Y32kmtn2LO8SsJcJmDFaD63sj3+WbTR+BRw0QZf9lE94Fa/MPooF0I49aNIx59Wa
2uRR9r0oBgMkpNH+kNmCXcRdPyWIbILGZShkKMcp0Oo=
/ *以下步骤描述用于签名然后验证签名* /
的openssl命令行/ * *****第1步:签署消息***** * /
/ *使用在* /
之前生成的RSA私钥来唱出消息dgst -sha512 -sign '/PATH...private_key.pem' -out '/PATH.../PKGC_sample_signed.binr' '/PATH.../sample.txt'
/ * Base64编码签名* /
base64 -in '/PATH.../PKGC_sample_signed.binr' -out '/PATH.../PKGC_sample_singed.enc64'
/ * *****第2步:签名验证***** * /
/ * Base64解码签名* /
base64 -d -in '/PATH.../PKGC_sample_singed.enc64' -out '/PATH.../PKGC_sample_signed.decod64'
/ *使用公钥* /
验证签名dgst -sha512 -verify '/PATH.../public_key.pem' -signature '/PATH.../PKGC_sample_signed.decod64' '/PATH.../sample.txt'
==&GT;我得到验证确定。