I'm trying to use the Botan library to create a SHA-256 hash of a couple QStrings - a password and a salt. I have made many attempts trying to get a concatenated salt+password into the correct type for input into the Botan process function. The documentation for the class I'm trying to use in Botan is found at botan sha-256 documentation My latest attempt is
///
/// Computes salted data hash
///
QByteArray MyClass::HashData(QString salt, QString password)
{
QString concatenated = salt+password;
QByteArray input(concatenated.toLocal8Bit());
Botan::SHA_256 sha;
Botan::SecureVector<Botan::byte> saltedHash
= sha.process(&input,input.count()-1); // -1 to get rid of the \0
return QByteArray(saltedHash);
}
When I compile I get an error: no matching function for call to 'Botan::SHA_256::process(QByteArray*, int)'... candiates are: /usr/include/botan-1.10/botan/buf_comp.h:101: Botan::SecureVector Botan::Buffered_Computation::process(const byte*, size_t)
How can I cast or copy a QString or a QByteArray into a const byte*?
EDIT: After I posted the question I tried a few more approaches. One that appears to work is attached below, but I'm uncomfortalbe using the reinterpret_cast because it seams like it could lead to problems that I'm not aware of in my c++ noob state.
Botan::SecureVector<Botan::byte> MyClass::HashData(QString salt, QString password)
{
QString concatenated = salt+password;
QByteArray buffer(concatenated.toLocal8Bit());
unsigned char * input = reinterpret_cast< unsigned char*>(buffer.data());
Botan::SHA_256 sha;
Botan::SecureVector<Botan::byte> saltedHash
= sha.process(input,buffer.count()-1); // -1 to get rid of the \0
return (saltedHash);
}
You can use the following method.