Wednesday 15 May 2013

openssl - rsa encryption decryption using c -


I am trying to write c code for encryption and decryption by using open SSL. But I am not able to do this. I went to it, but whatever code received from the internet was out of my head. The main function goes here that I got from the stack overflow. I tried to use it ?? But | I could be 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 & lt; 2) {fprintf (stderr, "Usage:% s & lt; PEM RSA public file & gt; \ 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, "PEM RSA Public Error loading file. \ N"); Exit (2); } RV = Encrypt (RSA_PP_FILE, INF.TXT, standout); Fclose (rsa_pkey_file); Return RV .; }   

and similarly decryption.

How can I make the RSA encryption and decryption of the file using CRM open SSL library in an easy way? The steps for RSA encryption are as follows:

  1. Read the public key in the RSA * structure. It depends on your main nature. If the key is in the format PEM , then use the PEM_read_RSA_PUBKEY function. If it's in the DER form, then use d2i_RSA .
  2. Encrypt your data using the RSA public key. RSA_public_encrypt function.
  3. Write a file or type what you want to do.

    RSA decryption steps are as follows:

    1. Read the private key in the RSA * structure . This is similar to Stage 1 in RSA encryption with some minor differences.
    2. Decrypt the data using RSA_private_decrypt . Use RSA_private_decrypt .

      You can see the OpenSSL documentation which is quite useful and its knowledge is intuitive. I just give you a broad level of consideration if you need more help, then I posted the code example I can do

No comments:

Post a Comment