我正在尝试使用Botan库来创建一对QStrings的SHA-256散列-一个密码和一个salt。我做了很多尝试,试图将级联的salt+password输入到Botan函数的正确类型中。我试图在Botan中使用的类的文档可以在博坦沙-256文件上找到,我最近的尝试是
///
/// 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);
}当我编译时,我得到一个错误:没有调用'Botan::SHA_256::process(QByteArray*,int)‘的匹配函数.候选名单为: /usr/include/botan-1.10/botan/buf_comp.h:101: Botan::SecureVector Botan::Buffered_Computation::process(const字节*,size_t)
如何将QString或QByteArray转换或复制到const字节*
编辑:在我发布了这个问题之后,我尝试了更多的方法。下面附了一个看起来有效的,但是我不喜欢使用reinterpret_cast,因为它的接缝可能会导致我在c++ noob状态中没有意识到的问题。
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);
}发布于 2012-10-12 03:16:44
您可以使用以下方法。
const char * QByteArray::data()发布于 2012-10-12 17:02:09
同样的问题是:*
但是为什么不使用reinterpret_cast,例如这样:
..。QString salt = "salt";QString密码=“密码”;QString串联=QString(“%1%2”).arg(Salt).arg(密码);无符号字符* input =(无符号字符*)连接。toLocal8Bit().data();printf("%s",输入);
https://stackoverflow.com/questions/12851441
复制相似问题