Question

I'm porting a portion of a .NET application to Qt on Linux. I am trying to replicate the results of a .NET function to create the SHA-256 hash of a password + salt. The .NET code is

return new SHA256Managed().ComputeHash(buffer);

I have code that creates the hash but it isn't in a form that will allow me to embed it in a json object.

// create the hash of the salt+password
Botan::SecureVector<Botan::byte> passwordHash = HashData(salt,StringToArray(m_password));
// convert to a QByteArray
QByteArray qPasswordHash;
for(uint i=0; i<passwordHash.size();++i){
    qPasswordHash[i]= passwordHash[i];
}

For reference, the StringToArray method is shown below

QByteArray StringToArray(QString szInput){
    QByteArray buffer = szInput.toUtf8().data();
    return buffer;
}

Does the qPasswordHash need to be put through a Base64 filter such as the one shown in the Documentation in order to match the output from the .NET class? If so is could you point me to example code or provide an example of the correct syntax for using this Botan method?

Was it helpful?

Solution

The most common way is to use hex-encoding, i.e. each byte is represented as 2-hexademical digits in string. And this is easier in implementation than Base64.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top