Hi there,
I want to read 1 byte of information, in the form of an array of unsigned chars [1], from a file. I then want to use this piece of data to act as a secret key for a message authentication code I will be performing. The key will be a 20 byte array of unsigned chars [20].
At the moment I have this as my key:
memset( key, 0x0b ,20);
It is basically 0b repeated x 20 to make up a 20 byte key:
0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b
But instead I want to store they key in a file and read it from there rather than hard code it in.
Here is what I am doing at the moment. I have saved '0x0b' in a .dat file, that is the files only content.
std::fstream myFile("/home/adam/Documents/cryptopp/mackeystring.dat",std::ios::app);
myFile.open("/home/adam/Documents/cryptopp/mackeystring.dat");
if (! myFile) // Always test file open
{
std::cout << "Error opening output file\n";
return -1;
}
//char *key;
std::string keystring;
getline(myFile,keystring);
unsigned char sequence [1];
memcpy(sequence,&keystring,1);
myFile.close();
memset( key, sequence ,20);
But it says that an unsigned char etc can not be used as an integer in the 2nd command of the memset. Although it worked fine when '0x0b' was hard coded into it. The code is opening and getting some data ok from the file, but I just need it converted to an array of unsigned chars ok, and for it to be accepted as my key.
Basically I want to replace 0x0b with the variable, sequence, and retrieve the value of 'sequence' from a file, instead of having it hard coded in. And its value should be a 20 byte array of unsigned chars: ie = 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
Any help with this would be great,
Thanks.