#include "stdafx.h"
#include <conio.h>
#include <openssl/rsa.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <stdlib.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
RSA *myrsa;
unsigned long e = RSA_3;
BIO* out = NULL
FILE* fp;
myrsa = RSA_generate_key(2048,e,NULL,NULL);
out=BIO_new(BIO_s_file());
if(myrsa==NULL){
printf("error in generating keypair..");
printf("press any key to exit..");
_getch();
}
fp=fopen("rsakeypair.txt","wb");
out = BIO_new_fp(fp,BIO_CLOSE);
BIO_printf(out,"\n");
RSA_print(out,myrsa,0);
fclose(fp); _getch(); return(0);
}
The above example program generates a 2048 bit RSA Key pair. It also generates the p,q,n,e and d sections into the text file. In order to build this sample using Visual C++, you will need to build OpenSSL first. After you build OpenSSL, you can then include the generated headers to your VC/Include folder. You will also need to include the the lib files generated by OpenSSL onto VC/Lib. The above example program is written in VS05. OpenSSL simply rocks!
Code + Demo + ReadmeFile : Here