Sto provando a generare una chiave pubblica rsa da un tipo di modulo char [], e ora l'esponente è RSA_F4 (65537); Ma quando sto cercando di generare la mia chiave pubblica usando questi valori di "n" ed "e", il RSA_public_encrypt, restituire -1;Come creare una chiave pubblica RSA da un modulo char * ed esponente 65537 (RSA_F4)
Grazie!
Il mio codice:
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <crypt.h>
#include <iostream>
#include <stdlib.h>
#include <openssl/rsa.h>
#include <openssl/aes.h>
#include <openssl/opensslconf.h>
#include <openssl/engine.h>
#include <openssl/pem.h>
#include <openssl/rc4.h>
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;
}
Sembra che tu leggere il tuo modulo in 'x', che non hai mai dichiara, lasciando' modul' come 0. È inoltre mai messo il modulo in 'pubkey', così è probabilmente ancora vuoto, dandoti un errore quando y prova a chiamare "RSA_public_encrypt". Se vuoi un aiuto concreto, devi pubblicare il codice reale che hai provato a compilare ed eseguire. –
dispiace ma il mio ultimo post è stato inserito per un errore. –