C语言——基于OpenSSL 的RSA 签名验签算法

        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
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值