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