OpenSSL开源工程中,实现RSA签名方法有多种。该方法基于OpenSSL 3.0版本,调用OpenSSL EVP层的EVP_DigestSign*()与EVP_DigestVerify*()实现pss填充方式的RSA消息签名。消息摘要采用sha256计算,pss中的GMF1采用sha224计算。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include< openssl/rsa.h>
#include <openssl/evp.h>
int rsa_sign_test()
{
unsigned char plaintext[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
unsigned int p_text_len = sizeof(plaintext) - 1;
unsigned char sig[256];
unsigned int signLen = 0;
int rv = 0;
BIGNUM *e = NULL;
RSA *r = NULL;
EVP_MD_CTX *mdctx = NULL;
EVP_PKEY *evpkey;
/** 生成RSA公私钥对 **/
e = BN_new();
BN_set_word(e, 65537);
r = RSA_new();
int bits = 1024;
if (RSA_generate_key_ex(r, bits, e, NULL) != 1)
{
printf("RSA_generate_key_ex is failed.\n");
rv = -2;
goto end;
}
evpkey = EVP_PKEY_new();
if(evpke


1234

被折叠的 条评论
为什么被折叠?



