title: C - Encrypt and decrypt a string with AES
body: <p>I'm trying to understand how to use <a href="https://github.com/kokke/tiny-AES-c" rel="nofollow noreferrer">this c library</a> (<strong>tiny-AES-c</strong>). As a web developer, I'm looking to get an equivalent C code for <a href="https://jsfiddle.net/gcdfs3oo/112/" rel="nofollow noreferrer">this JS fiddle</a>.</p>
  
  <p>The JS code is straightforward:</p>
  
  <pre><code>// Encrypt
  var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123');
  
  
  console.log("Encrypted: " + ciphertext.toString());
  
  // Decrypt
  var bytes  = CryptoJS.AES.decrypt(ciphertext.toString(), 'secret key 123');
  var plaintext = bytes.toString(CryptoJS.enc.Utf8);
  
  console.log("Decrypted: " + plaintext);
  </code></pre>
  
  <p>Given a message to encrypt and a secret, the code generates the encrypted data and transform the results to a string.</p>
  
  <hr>
  
  <p>My C code:</p>
  
  <pre><code>int main()
  {
      uint8_t in[]  = "my message";
      uint8_t key[] =  "secret key 123";
  
      struct AES_ctx ctx;
  
      AES_init_ctx(&amp;ctx, key);
      printf("ORIG: %s",(char*) in);
  
      // Encrypt
      AES_ECB_encrypt(&amp;ctx, in);
      printf("\nENC: %s",(char*) in);
  
      // Decrypt
      AES_ECB_decrypt(&amp;ctx, in);
      printf("\nDEC: %s",(char*) in);
  
      return 0;
  }
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>ORIG: my message
  ENC: ̤�+��5&lt;n]EYK�ظ/����
  DEC: my message%  
  </code></pre>
  
  <p>I understand that I shouldn't try to print the result as a string, but couldn't figure out how to get similar (to the JS) results, using the <strong>tiny-AES-c</strong> API, plus when I tried using longer messages I got strange results, leading me to think I'm using this library the wrong way.</p>
  
  <p><strong>Q</strong>: What would be the C code equivalent to the above JS?</p>