Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Botan和Qt加密文件时出错_C++_Qt_Cryptography_Botan - Fatal编程技术网

C++ 使用Botan和Qt加密文件时出错

C++ 使用Botan和Qt加密文件时出错,c++,qt,cryptography,botan,C++,Qt,Cryptography,Botan,我正在尝试使用“Botan”加密和解密文件(AES 256)。成功地将库集成到Qt中。我在互联网上找到了很多这样的例子,但我得到了以下结果 error: class Botan::S2K' has no member named 'set_iterations' 我发现为其创建教程的Botan版本已经过时,并且我正在使用的版本(1.10.5)不兼容 我的问题是: 在哪里可以找到新版本的教程?如果没有,我在哪里可以下载以前版本(1.8或1.9)的windows installer 以下是我目前

我正在尝试使用“Botan”加密和解密文件(AES 256)。成功地将库集成到Qt中。我在互联网上找到了很多这样的例子,但我得到了以下结果

error: 
class Botan::S2K' has no member named 'set_iterations'
我发现为其创建教程的Botan版本已经过时,并且我正在使用的版本(1.10.5)不兼容

我的问题是:
在哪里可以找到新版本的教程?如果没有,我在哪里可以下载以前版本(1.8或1.9)的windows installer

以下是我目前的代码: (加密)

string文件=“…”;
字符串fileEncrypted=“…”;
植物学:图书馆初始化器初始化;
字符串passphrase=“password”;
自动进料;
S2K*S2K=get_S2K(“PBKDF2(SHA-256)”;
s2k->set_迭代(4049);
SecureVector key_和_IV=s2k->deriver_key(48,密码短语);
SymmetricKey键(键U和键IV,32);
初始化向量iv(键_和_iv+32,16);
std::ifstream-in(文件,std::ios::binary);
std::ofstreamout(文件加密,std::ios::二进制);
管道(获取密码(“AES-256/CBC”,密钥,iv,加密),新的数据链(out);
pipe.start_msg();
在>>管道中;
pipe.end_msg();

您可以从获得1.9版,但恐怕您在使用新版本时遇到两个问题:

  • get_s2k()
    已经过时,您应该改用
    get_pbkdf()

  • 当使用PBKDF而不是不推荐使用的S2k时,可以将迭代次数传递给版本中的派生_键,而不是使用mutator方法设置迭代

请参见他们的encrypt2示例,例如:

...
PKCS5_PBKDF2 pbkdf2(new HMAC(new SHA_160));

const u32bit PBKDF2_ITERATIONS = 8192;

SecureVector<byte> salt(8);
rng.randomize(&salt[0], salt.size());

SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase,
                                                 &salt[0], salt.size(),
                                                 PBKDF2_ITERATIONS).bits_of()
...
。。。
PKCS5_PBKDF2 PBKDF2(新HMAC(新沙乌160));
常量u32位PBKDF2_迭代=8192;
食盐(8);
随机分配(&salt[0],salt.size());
SecureVector主密钥=pbkdf2。派生密钥(48,密码短语,
&salt[0],salt.size(),
PBKDF2_迭代)
...

您可以在
doc/examples
文件夹中查看更多的示例,了解详细信息,然后获取它们的版本并将其解压缩。

thx以获取答案。我遵循encrypt2示例,让我的程序生成,但当我运行它时,它会崩溃!我猜Botan与Qt的集成毕竟不是没有错误的。我最终使用了这个站点的源代码:它使用了Botan的合并版本,并且与Qt 5.2完美配合(只需更改toLatin1()中的去擦洗toAscii()函数)
...
PKCS5_PBKDF2 pbkdf2(new HMAC(new SHA_160));

const u32bit PBKDF2_ITERATIONS = 8192;

SecureVector<byte> salt(8);
rng.randomize(&salt[0], salt.size());

SecureVector<byte> master_key = pbkdf2.derive_key(48, passphrase,
                                                 &salt[0], salt.size(),
                                                 PBKDF2_ITERATIONS).bits_of()
...