title: Encryption and Decryption using C++
body: <p>I've got a buffer, in which i'm adding some plain text.
  I want to use openssl AES encryption to encrypt the text, then decrypt it, and print it back on the screen.</p>
  
  <p>Code is running with no errors.</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  #include &lt;openssl/aes.h&gt;
  using namespace std;
  
  void main()
  {
  
  // Buffers
  unsigned char inbuffer[1024];
  unsigned char encryptedbuffer[1024];
  unsigned char outbuffer[1024];
  
  
  // CODE FOR ENCRYPTION
  //--------------------
  unsigned char oneKey[] = "abc";
  AES_KEY key; 
  
  AES_set_encrypt_key(oneKey,128,&amp;key);
  AES_set_decrypt_key(oneKey,128,&amp;key);
  
  //--------------------
  
  
  string straa("hello world\n");
  memcpy((char*)inbuffer,straa.c_str(),13);
  
  
  printf("%s",inbuffer);
  //this prints out fine
  
  AES_encrypt(inbuffer,encryptedbuffer,&amp;key);
  //printf("%s",encryptedbuffer);
  //this is expected to pring out rubbish, so is commented
  
  AES_decrypt(encryptedbuffer,outbuffer,&amp;key);
  printf("%s",outbuffer);
  //this is not pringint "hello world"
  
  getchar();
  
  }
  </code></pre>
  
  <p>I am aware of the fact that once placed in the new buffers, "encryptedbuffer" and "outbuffer", they are not null terminated "\0" , but even so, by printing out the raw data, i'm only getting rubbish after the decryption,
  At the end of the decryption, i'm assuming the \0 should also be decrypted and therefore the printf should print corectly.</p>
  
  <p>Anyone knows how to make the decyption work?</p>
  
  <p>Also any idea how to print the buffers using C++ libraries, maybe cout, and not printf?</p>