I'm trying to write C code of RSA encryption and decryption using Open SSL. But I am not able to do so. I googled it but whatever code I got from internet it was out of my head.
main
function goes here which I got from stack overflow. I tried using it … but its not working. May be my bad.
encrypt(FILE *rsa_Pkey_fole,FILE *in_file,FILE *out_file){
}
int main(int argc, char *argv[])
{
FILE *rsa_pkey_file, *infile;
int rv;
if (argc < 2) {
fprintf(stderr, "Usage: %s <PEM RSA Public Key File>\n", argv[0]);
exit(1);
}
rsa_pkey_file = fopen(argv[1], "rb");
infile = fopen(argv[2], "w");
if (!rsa_pkey_file) {
perror(argv[1]);
fprintf(stderr, "Error loading PEM RSA Public Key File.\n");
exit(2);
}
rv = encrypt(rsa_pkey_file, infile.txt, stdout);
fclose(rsa_pkey_file);
return rv;
}
And similar way decryption.
How can I do RSA encryption and decryption of a file using Open SSL library in C in simple way?