我想知道你是否可以帮我解决一个小问题:
我目前正在使用C ++ / Qt,并收到以下错误消息:
P:\Produkt\Savor_V100\webapi.cpp:84: error: C2664: 'CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey' : cannot convert parameter 1 from 'const char *' to 'byte *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
函数中的参数未被使用,因此我想在那里传递一个空字节。经过一番研究后我发现一个字节只是一个简单的unsigned char?
我的代码如下所示:
byte* unused;
qDebug() << CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey(CryptoPP::SHA1::StaticAlgorithmName(), CryptoPP::SHA1::BLOCKSIZE, unused, user->getPassword(), sizeof(user->getPassword()), user->getSerial(), sizeof(user->getSerial()), 0 );
答案 0 :(得分:2)
如评论中所述,这里的问题是函数的第一个参数,而不是使用unused
的第三个参数。由于我猜你确实需要这个参数,你应该按照建议尝试:
qDebug() << CryptoPP::PasswordBasedKeyDerivationFunction::DeriveKey(
reinterpret_cast<byte*>(CryptoPP::SHA1::StaticAlgorithmName()),
CryptoPP::SHA1::BLOCKSIZE,
0,
user->getPassword(),
sizeof(user->getPassword()),
user->getSerial(),
sizeof(user->getSerial()),
0 );