In my quest for a single header encryption library for c++ I found this github repo that uses AES with CBC mode to encrypt a std::string
into a vector of unsigned char
in the example provided in the repo this
const unsigned char iv[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
};
initialization vector was used, now the encrypted data is ready to be sent to the api with the endpoint /data
that accepts data in JSON format
{"data":"encrypted-data"}
and decryptes it for later use
the server where the data is sent is written in python and uses the following lines to decrypt the data
obj2 = AES.new('EncryptionKey128'.encode("utf8"), AES.MODE_CBC, 'This is an IV456'.encode("utf8"))
result = obj2.decrypt(phrase)
print (result)
how to convert the iv to a string to use on the server side
if tried looping over the items in
lst = [ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F]
for item in lst:
item = item.replace('0x','')
bytes_object = bytes.fromhex(item)
ascii_string = bytes_object.decode("utf-8")
but this create an iv that is larger than 16 chars
Goal behind this is to encrypt a string with AES and send it to a python server to be decrypted for the sake of this example both keys will be hardcoded in the server and the client