c语言 int -65537,c – 如何从unsigned char *模数和指数65537(RSA_F4)创建RSA公钥

我正在尝试从模数类型char []生成一个rsa公钥,现在我的指数是RSA_F4(65537);

但是,当我尝试使用“n”和“e”的值生成我的公钥时,RSA_public_encrypt,返回-1;

谢谢!

我的代码:

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

int main(void)

{

//modulus in format char hex;

char key[] = "C0E7FC730EB5CF85B040EC25DAEF288912641889AD651B3707CFED9FC5A1D3F6C40062AD46E3B3C3E21D4E71CC4800C80226D453242AEB2F86D748B41DDF35FD";

char palavra[] = "teste";

char crip[512];

int ret;

RSA * pubkey = RSA_new();

BIGNUM * modul = BN_new();

BIGNUM * expon = BN_new();

BN_hex2bn(&modul, (const char *) key);

BN_hex2bn(&expon, "010001");

cout << "N KEY: " << BN_bn2hex(modul) << endl;

cout << "E KEY: " << BN_bn2hex(expon) << endl;

pubkey->n = modul;

pubkey->e = expon;

cout << "N PUB KEY: " << BN_bn2hex(pubkey->n) << endl;

cout << "E PUB KEY: " << BN_bn2hex(pubkey->e) << endl;

if (RSA_public_encrypt(strlen((const char *) palavra), (const unsigned char *) palavra, (unsigned char *) crip, pubkey, RSA_PKCS1_PADDING ))

{

printf("ERRO encrypt\n");

}

else

{

printf("SUC encrypt\n");

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值