Hi,
I have to write back rsa public/private key to calling function, i have
tried below program using i2d_RSAPrivatekey().
My application will not accept RSA * structure, it will accept only char or
strings to be return as s key.
#include <stdio.h>
#include <string.h>
#include <openssl/rsa.h>
typedef struct {
unsigned char cl_priv[1000];
} DER_RSA;
generate(DER_RSA *ctr)
{
RSA *rsa, *pub_rsa, *priv_rsa;
unsigned char keybuf[512], *p;
int len;
// DER_RSA *ctr;
printf("hello");
rsa = RSA_generate_key(512, RSA_F4,NULL,NULL);
/* get separated der key pair */
p=ctr->cl_priv;
len=i2d_RSAPrivateKey(rsa,&p);
printf("\nlen=%d\n",len);
return ;
RSA_free(rsa);
}
int main()
{
int i;
DER_RSA *ctr;
generate(ctr);
printf("pubkey=%s",ctr->cl_priv);
}
the output is ,
$ ./first
hello
len=317
pubkey=(null)
while encrypting i will get same value and length: using d2i_RSAPrivatekey()
function convert into RSA *privkey then use RSA_private_encrypt() to encrypt
the message.
is it possible? here pubkey is returning null. how i can check pubkey buffer
has value.
Thanks in advance,
kris