I am using a library called botan for encryption. but the case here is not related with the library, it seems to be a issue in c++ or casting. using the library a 16 byte long vector is created as below.
SecureVector<byte> salt = rng.random_vec(16);
then it is converted to a string as,
std::string salt_string ((const char*)salt.begin() , salt.size());
using Qt i can just read the srting as,
ui->textEdit->append("Salt is : "+ QString::fromStdString(salt_string));
now I need to write this to a file and regenerate the vector at a later time. It is written to a file as,
ofstream outfile ("salt.txt" , std::ios::binary);
outfile.write((const char*)salt.begin(), salt.size());
up to this point the code looks working great and the problem occurs when reading and regenerating the vector.
here is how i read the data to a char* array,
ifstream infile ("salt.txt" , std::ios::binary );
char* salt = new char[16];
infile.read(salt , 16 );
now I need to recreate the SecureVector<byte>
as salt2 , I tried to do it using reinterpret_cast
as below,
SecureVector<byte> salt2 = reinterpret_cast<byte> (salt);
which compiles without errors but returns a empty string when try to display as i displayed salt above. what am i doing wrong or how to do the conversion correctly. any help or advice will be highly appreciated.