title: Proper way to encrypt a file with openssl using the EVP api in C
body: <p>What I am trying to do:
  Encrypt an executable, then decrypt it later.</p>
  
  <p>What my problem is:
  looping properly through the exe.</p>
  
  <p>Here is what my code currently looks like:</p>
  
  <pre><code>  unsigned char ckey[] =  "thiskeyisverybad";
    unsigned char ivec[] = "dontusethisinput";
  //Initiate the EVP interface
  EVP_CIPHER *c = EVP_aes_256_cbc();
  //Initialize symmetric cypher
  EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX) malloc(sizeof(EVP_CIPHER_CTX));
  EVP_CIPHER_CTX_init(ctx);
  //Set up cypher contex
  EVP_EncryptInit(ctx,c,ckey,ivec);
  </code></pre>
  
  <p>Of course there are better ways to set up the key and the iv (I am looking at the book network security with openssl). This is not my problem, my problem is how should I properly load up an exe, and encrypt it. From my understanding I should open it up in rb mode and read it. What I dont understand is what size chunks I should be using. I understand that I must, when calling EVP_EncryptUpdate I have to enter in an input buffer and a buffer length. I would like to know how I should read the input exe. Should I loop through the file for and read one AES_BLOCK_SIZE per iteration? What would be the proper way to accomplish this?</p>