user11207: Okay, here's the story. I'm not very familiar with how Arduino works but learning. I have a project that requires AES encryption on the Arduino Uno. As per a previous question we managed to figure out the problem but failed to resolve it fully so we started using another library. (This one: https://github.com/qistoph/ArduinoAES256)
uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };
Now onto the problem itself. Using an online AES encryption tool such as: http://aesencryption.net/ Simply asks for a Key of the encryption in plain text and the output is base64 as specified by the service here: The result of the encryption will appear in base64 encoded to prevent character encoding problems.

Also, plain text can be used to process the encryption using AES algorithm.
I've been trying to achieve the exact same result using an Arduino Uno board with the exact same requirements. The end result is to have a base64 string that can be decrypted on another remote location having the same key.
Now as for the .ino file it has this setup:
#include "aes256.h" //Include library files
#define DUMP(str, i, buf, sz) { Serial.println(str); \
    for(i=0; i<(sz); ++i) { if(buf[i]<0x10) Serial.print('0'); Serial.print(char(buf[i]), HEX); } \
    Serial.println(); } //Help function for printing the Output

aes256_context ctxt;

void setup() {
  int i;
  Serial.begin(9600);

  Serial.println("Initializing AES256... ");
  uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };
  DUMP("Key: ", i, key, sizeof(key));
  aes256_init(&ctxt, key);

  uint8_t data[] = { //"asdfasdfasdfasdf"
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66,
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66
  };
  DUMP("Unencrypted data: ", i, data, sizeof(data));

  aes256_encrypt_ecb(&ctxt, data);
  DUMP("Encrypted data: ", i, data, sizeof(data));

  aes256_decrypt_ecb(&ctxt, data);
  DUMP("Back decrypted data: ", i, data, sizeof(data));

  aes256_done(&ctxt);
}

void loop() {
}


1) I can't seem to understand what is required to have a plain text key and plain text message to encrypt giving an end result of base64 output.
For example if I were to do this using JavaScript: (And this is just an example).

2) I'd like to achieve something like this:
var key = "32 characters plain text here";
var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
var base64_output = aes.encrypt256(key, plain);


3) I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino. - Is this impossible to achieve? We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message.

Any help is greatly appreciated. If someone doesn't mind us contacting them over the phone we would also greatly appreciate a phone call to have this issue explained and resolve so we can share our experience with the Arduino community.
Thanks in advance.
edit:
We're getting this error

edit2:
Thank you @Nick Gammon for the quick response.
After removing const from the function 4 places and the key variable declaration, everything seems to be working fine now.
We modified the code in order to print all bytes for each cipher block. We have this output:
140 145 154 38 228 66 98 128 116 68 245 193 70 84 205 115 
Œ‘š&äBb€tDõÁFTÍsŒ‘š&äBb€tDõÁFTÍs
186 174 17 21 162 83 96 210 128 134 46 206 172 215 0 103 
º®¢S`Ò€†.Î¬×
112 4 216 150 27 202 6 176 77 159 123 231 127 128 32 132 
pØ–Ê°MŸ{ç€ „pØ–Ê°MŸ{ç€ „
215 110 118 33 167 193 212 121 156 46 63 139 183 124 63 152 
×nv!§ÁÔyœ.?‹·|?˜×nv!§ÁÔyœ.?‹·|?˜
130 91 174 118 4 202 250 74 228 7 173 40 246 124 53 173 
‚[®vÊúJä­(ö|5­‚[®vÊúJä­(ö|5­
231 48 204 82 235 172 202 139 33 134 137 81 209 191 210 217 
ç0ÌRë¬Ê‹!†‰QÑ¿ÒÙç0ÌRë¬Ê‹!†‰QÑ¿ÒÙ
184 161 98 135 12 230 86 213 183 113 103 234 187 213 224 133 
¸¡b‡æVÕ·qgê»Õà…¸¡b‡æVÕ·qgê»Õà…
Done

We're trying to convert each array of bytes into a char array of hex values then base_64 encode it.  But we're getting this output which is not what we want. Can you please explain how can we achieve this.
Please let us know if it is possible to open a chat with you so that we can understand this better.

user10794: 
We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message.

To address this question/issue, below is some code that will take an arbitrary length string and break it into 16-character strings suitable for encoding with AES:
const int KEY_SIZE = 32;
const int BLOCK_SIZE = 16;
const char message [] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
const byte key [KEY_SIZE] = "32 characters plain text here";

void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE]);  // prototype
void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE])
  {
  // encrypt here
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  const char * p = message;

  while (strlen (p) > 0)
    {
    byte plain [BLOCK_SIZE];
    memset (plain, 0, BLOCK_SIZE);  // ensure trailing zeros
    // copy block into plain array
    memcpy (plain, p, min (strlen (p), BLOCK_SIZE));
    // encrypt it
    encrypt_it (plain, key);
    // advance past this block
    p += min (strlen (p), BLOCK_SIZE);
    }
  Serial.println ("Done");
  }  // end of setup

void loop ()
  {
  }  // end of loop



I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino. - Is this impossible to achieve?

Of course it is possible. Just look up (Google) a C or C++ function to base-64 encode a string. There must be thousands of them. This is not an Arduino question, this is a C programming question.


As per a previous question we managed to figure out the problem but failed to resolve it fully ...

Namely here: Implementing DES or AES Encryption with DateTime Synchronization on Uno.
This question actually looks remarkably similar to your previous one.

user4143: 
2) I'd like to achieve something like this:

  var key = "32 characters plain text here";
  var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
  var base64_output = aes.encrypt256(key, plain);
  

So do it.
#define MAX_MESSAGE_SIZE 256
uint8_t key[] = "32 characters plain text here";
uint8_t plain[MAX_MESSAGE_SIZE+1] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
aes256_init(&ctxt, key);
aes256_encrypt_ecb(&ctxt, plain);
// plain is now encrypted.

That is limited to a maximum message (and encrypted output) size of 256 bytes due to the (purely arbitrary) size of the array I chose.

11207: <p>Okay, here's the story. I'm not <strong>very</strong> familiar with how Arduino works but learning. I have a project that requires AES encryption on the Arduino Uno. As per a previous question we managed to figure out the problem but failed to resolve it fully so we started using another library. (This one: <a href="https://github.com/qistoph/ArduinoAES256" rel="nofollow noreferrer">https://github.com/qistoph/ArduinoAES256</a>)</p>

<p><code>uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };</code></p>

<p>Now onto the problem itself. Using an online AES encryption tool such as: <a href="http://aesencryption.net/" rel="nofollow noreferrer">http://aesencryption.net/</a> Simply asks for a <code>Key of the encryption</code> in <strong>plain text</strong> and the output is <code>base64</code> as specified by the service here: <code>The result of the encryption will appear in base64 encoded to prevent character encoding problems.
</code>
Also, <strong>plain text</strong> can be used to process the encryption using <code>AES</code> algorithm.</p>

<p>I've been trying to achieve the exact same result using an <code>Arduino Uno</code> board with the exact same requirements. The end result is to have a <code>base64</code> string that can be decrypted on another remote location having the same <code>key</code>.</p>

<p>Now as for the <code>.ino</code> file it has this setup:</p>

<pre><code>#include "aes256.h" //Include library files
#define DUMP(str, i, buf, sz) { Serial.println(str); \
    for(i=0; i&lt;(sz); ++i) { if(buf[i]&lt;0x10) Serial.print('0'); Serial.print(char(buf[i]), HEX); } \
    Serial.println(); } //Help function for printing the Output

aes256_context ctxt;

void setup() {
  int i;
  Serial.begin(9600);

  Serial.println("Initializing AES256... ");
  uint8_t key[] = { //
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
    0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
  };
  DUMP("Key: ", i, key, sizeof(key));
  aes256_init(&amp;ctxt, key);

  uint8_t data[] = { //"asdfasdfasdfasdf"
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66,
    0x61, 0x73, 0x64, 0x66, 0x61, 0x73, 0x64, 0x66
  };
  DUMP("Unencrypted data: ", i, data, sizeof(data));

  aes256_encrypt_ecb(&amp;ctxt, data);
  DUMP("Encrypted data: ", i, data, sizeof(data));

  aes256_decrypt_ecb(&amp;ctxt, data);
  DUMP("Back decrypted data: ", i, data, sizeof(data));

  aes256_done(&amp;ctxt);
}

void loop() {
}
</code></pre>

<hr>

<h3>1) I can't seem to understand what is required to have a <code>plain text</code> key and <code>plain text</code> message to encrypt giving an end result of <code>base64</code> output.</h3>

<p>For example if I were to do this using <code>JavaScript</code>: (And this is just an example).</p>

<hr>

<h3>2) I'd like to achieve something like this:</h3>

<pre><code>var key = "32 characters plain text here";
var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
var base64_output = aes.encrypt256(key, plain);
</code></pre>

<hr>

<h3>3) <strong>I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino.</strong> - Is this impossible to achieve? We've been trying for some time now from endless conversions to splitting up our <code>plain</code> text into chunks of 16 characters so that we can encrypt the message.</h3>

<hr>

<p>Any help is greatly appreciated. If someone doesn't mind us contacting them over the phone we would also greatly appreciate a phone call to have this issue explained and resolve so we can share our experience with the Arduino community.</p>

<p>Thanks in advance.</p>

<h2>edit:</h2>

<p>We're getting this error
<img src="https://i.stack.imgur.com/x4Xm7.png" alt="enter image description here"></p>

<h2>edit2:</h2>

<p>Thank you @Nick Gammon for the quick response.
After removing const from the function 4 places and the <code>key</code> variable declaration, everything seems to be working fine now.
We modified the code in order to print all bytes for each cipher block. We have this output:</p>

<pre><code>140 145 154 38 228 66 98 128 116 68 245 193 70 84 205 115 
Œ‘š&amp;äBb€tDõÁFTÍsŒ‘š&amp;äBb€tDõÁFTÍs
186 174 17 21 162 83 96 210 128 134 46 206 172 215 0 103 
º®¢S`Ò€†.Î¬×
112 4 216 150 27 202 6 176 77 159 123 231 127 128 32 132 
pØ–Ê°MŸ{ç€ „pØ–Ê°MŸ{ç€ „
215 110 118 33 167 193 212 121 156 46 63 139 183 124 63 152 
×nv!§ÁÔyœ.?‹·|?˜×nv!§ÁÔyœ.?‹·|?˜
130 91 174 118 4 202 250 74 228 7 173 40 246 124 53 173 
‚[®vÊúJä­(ö|5­‚[®vÊúJä­(ö|5­
231 48 204 82 235 172 202 139 33 134 137 81 209 191 210 217 
ç0ÌRë¬Ê‹!†‰QÑ¿ÒÙç0ÌRë¬Ê‹!†‰QÑ¿ÒÙ
184 161 98 135 12 230 86 213 183 113 103 234 187 213 224 133 
¸¡b‡æVÕ·qgê»Õà…¸¡b‡æVÕ·qgê»Õà…
Done
</code></pre>

<p>We're trying to convert each array of bytes into a <code>char</code> array of hex values then base_64 encode it.  But we're getting this output which is not what we want. Can you please explain how can we achieve this.
Please let us know if it is possible to open a chat with you so that we can understand this better.</p>
 10794: 

<blockquote>
  <p>We've been trying for some time now from endless conversions to splitting up our plain text into chunks of 16 characters so that we can encrypt the message.</p>
</blockquote>

<p>To address this question/issue, below is some code that will take an arbitrary length string and break it into 16-character strings suitable for encoding with AES:</p>

<pre class="lang-C++ prettyprint-override"><code>const int KEY_SIZE = 32;
const int BLOCK_SIZE = 16;
const char message [] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
const byte key [KEY_SIZE] = "32 characters plain text here";

void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE]);  // prototype
void encrypt_it (const byte plaintext [BLOCK_SIZE], const byte cipherkey [KEY_SIZE])
  {
  // encrypt here
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  const char * p = message;

  while (strlen (p) &gt; 0)
    {
    byte plain [BLOCK_SIZE];
    memset (plain, 0, BLOCK_SIZE);  // ensure trailing zeros
    // copy block into plain array
    memcpy (plain, p, min (strlen (p), BLOCK_SIZE));
    // encrypt it
    encrypt_it (plain, key);
    // advance past this block
    p += min (strlen (p), BLOCK_SIZE);
    }
  Serial.println ("Done");
  }  // end of setup

void loop ()
  {
  }  // end of loop
</code></pre>

<hr>

<blockquote>
  <p>I'd like to have the base64_output as base64 string so that it can be printed on a third-party printer hooked to the Arduino. - Is this impossible to achieve?</p>
</blockquote>

<p>Of course it is possible. Just look up (Google) a C or C++ function to base-64 encode a string. There must be thousands of them. This is not an Arduino question, this is a C programming question.</p>

<hr>

<blockquote>
  <p>As per a previous question we managed to figure out the problem but failed to resolve it fully ...</p>
</blockquote>

<p>Namely here: <a href="https://arduino.stackexchange.com/questions/13426/implementing-des-or-aes-encryption-with-datetime-synchronization-on-uno">Implementing DES or AES Encryption with DateTime Synchronization on Uno</a>.</p>

<p>This question actually looks remarkably similar to your previous one.</p>
 4143: <blockquote>
  <p>2) I'd like to achieve something like this:</p>
  
  <p><code>
  var key = "32 characters plain text here";
  var plain = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
  var base64_output = aes.encrypt256(key, plain);
  </code></p>
</blockquote>

<p>So do it.</p>

<pre><code>#define MAX_MESSAGE_SIZE 256
uint8_t key[] = "32 characters plain text here";
uint8_t plain[MAX_MESSAGE_SIZE+1] = "Unlimited characters text here that can be used by the library to encrypt this plain message variable";
aes256_init(&amp;ctxt, key);
aes256_encrypt_ecb(&amp;ctxt, plain);
// plain is now encrypted.
</code></pre>

<p>That is limited to a maximum message (and encrypted output) size of 256 bytes due to the (purely arbitrary) size of the array I chose.</p>
