Hello, > > Someone of you can tell me how can I extract public and private keys from RSA > structure returned by the function "RSA_generate_key"? > > I'm using openssl in my c++ simulation work and I must exchange public keys > between simulated server and client, I cannot exchange the whole RSA > structure!?
#include <stdio.h> #include <openssl/bn.h> #include <openssl/rsa.h> int main() { RSA *r; r = RSA_generate_key(32,656537,NULL,NULL); if( r==NULL ) { printf("Key failed"); exit(1); } else { printf("public modulus (n):\n"); printf(" %s\n",BN_bn2hex(r->n)); printf("public exponent (e):\n"); printf(" %s\n",BN_bn2hex(r->e)); printf("private exponent (d):\n"); printf(" %s\n",BN_bn2hex(r->d)); printf("secret prime factor (p):\n"); printf(" %s\n",BN_bn2hex(r->p)); printf("secret prime factor (q):\n"); printf(" %s\n",BN_bn2hex(r->q)); printf("dmp1 [ d mod (p-1) ]:\n"); printf(" %s\n",BN_bn2hex(r->dmp1)); printf("dmq1 [ d mod (q-1) ]:\n"); printf(" %s\n",BN_bn2hex(r->dmq1)); printf("iqmp [ q^-1 mod p ]:\n"); printf(" %s\n",BN_bn2hex(r->iqmp)); } printf("RSA SIZE: %d\n", RSA_size(r)); return(0); } Best regards, -- Marek Marcola <[EMAIL PROTECTED]> ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]