title: How to convert an array of 16-bit values to base64?
body: <p>So I'm working on an encryption/decryption method in C++ right now. It takes an <code>std::string</code> as an input (plus a "key" which will be used for encrypting the message), and it produces an <code>std::string</code> output which represents the encrypted string.</p>
  
  <p>During the encryption process, I convert the <code>std::string</code> to an array of <code>uint16_t</code> and do some calculations on that as a part of the encryption. The reason for that is simply because a <code>uint_16_t</code> value gives much more headroom to encrypt the original value via an algorithm then a <code>char</code> does.</p>
  
  <p>The problem is that in order to give back the encrypted message as an <code>std::string</code> I need to somehow convert the array of <code>uint_16_t</code> values to something readable (that is something that fits inside a <code>char</code> array without overflow). For that, I thought I could use base64 but all the base64 implementations I found only take <code>std::string</code> or <code>char*</code> as an input (8 bits/element). Obviously if I would provide it with my <code>uint16_t</code> array, I would never be able to get my original values back because the base64 function casts it down to 8 bits before converting it.</p>
  
  <p><strong>So here's my question:</strong> does anyone know a method of encoding a <code>uint16_t</code> array into a printable string (like base64), and back without any loss of data?</p>
  
  <p>I know that I have to obtain the bytes of my data in order to use base64 but I'm not sure how to do that.</p>
  
  <p>Thanks for any help in advance!</p>