I am following a tutorial in which they use BIO_printf(bio_out,"%02x",bs->data[i] );
in order to get the characters of a serial number stored in bs->data
(which is an array of unsigned char) and they use "%02x"
to specify the format of the char. I am using c++ and I want to add each of these chars to a stringstream
but I can't find a way to translate the format and instead of a serial number I get ጄ냾�㮚㭖嵺ﭔ촋ᙰ
.
I have tried using
std::stringstream serial("Serial: ");
for (int i = 0; i < bs->length; i++)
{
serial << std::setw(2) << std::hex << bs->data[i] << std::endl;
}
but I still don't get a valid string, and
char* buffer = const_cast<char*>(serial.str().c_str());
sprintf(buffer, "%02x", bs->data[i]);
doesn't seem to work either (don't mind the const cast, I know it is bad practice)