c++创建空字节

C++ create empty byte

本文关键字:字节 创建 c++      更新时间:2023-10-16

我想知道您是否可以帮助我解决一个小问题:

我目前正在c++/Qt中开发,并得到以下错误信息:

P:ProduktSavor_V100webapi.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

函数中的参数没有使用,因此我想在那里传递一个空字节。经过一番研究,我发现字节只是一个简单的无符号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 );

正如评论中所说,这里的问题是函数的第一个参数,而不是您使用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 );