How to convert a String o another Hex String

You're overwriting HexString each time

sizeof(msgArray) - 1;

strlen would make more sense.