title: How to encrypt/decrypt larger file using RSA/AES
body: <p>Okay so i'm looking for a way to encrypt/decrypt larger files using RSA and AES.
  I don't quite understand what I need to do.</p>
  
  <p>The scenario is that i've got larger files (anywhere from 200kb - 50mb). I want to be able to encrypt specific files leaving a key (private key) in the current directory as well as the encrypted file. The user can then save the key, take it with them and come back to decrypt the file at a later time.</p>
  
  <p>I just don't quite understand how to use AES/RSA together to achieve this. I have some code to do simple RSA encryption/decryption and some working AES code. I got this code from other SO questions.</p>
  
  <p>I'm using Openssl with C++.</p>
  
  <p>Current AES program: (from online)</p>
  
  <pre><code>int main() {
  
  int bytes_read, bytes_written;
    unsigned char indata[AES_BLOCK_SIZE];
    unsigned char outdata[AES_BLOCK_SIZE];
  
    /* ckey and ivec are the two 128-bits keys necesary to
    en- and recrypt your data.  Note that ckey can be
    192 or 256 bits as well */
    unsigned char ckey[] = "thiskeyisverybad";
    unsigned char ivec[] = "dontusethisinput";
  
    /* data structure that contains the key itself */
    AES_KEY key;
  
    /* set the encryption key */
    AES_set_encrypt_key(ckey, 128, &amp;key);
  
    /* set where on the 128 bit encrypted block to begin encryption*/
    int num = 0;
  
    FILE *ifp = fopen("out.txt", "rb");
    FILE *ofp = fopen("outORIG.txt", "wb");
  
    while (true) {
      bytes_read = fread(indata, 1, AES_BLOCK_SIZE, ifp);
  
      AES_cfb128_encrypt(indata, outdata, bytes_read, &amp;key, ivec, &amp;num,
        AES_DECRYPT); //or AES_DECRYPT
  
      bytes_written = fwrite(outdata, 1, bytes_read, ofp);
      if (bytes_read &lt; AES_BLOCK_SIZE)
        break;
    }
  </code></pre>