编译Qt中的Botan示例时出错

时间:2013-08-17 08:01:42

标签: qt botan

我尝试使用Botan库加密文件,并编码以下内容:

#include <botan/botan.h>
#include <cstring>
#include <vector>
#include <iostream>
#include <memory>
#include <fstream>
#include <string>

using namespace Botan;
using namespace std;

void Encrypt(SymmetricKey key, InitializationVector iv,
             string inFilename, string outFilename)
{

}

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    qDebug() << "Starting Botan...";

    string filePlainText = "C:\\myfile.txt";
    string fileEncrypted = "C:\\encrypted.txt";
    string fileDecrypted = "C:\\decrypted.txt";

    string passphrase = "mypassword";

    Botan::LibraryInitializer init;
    AutoSeeded_RNG rng;

    S2K* s2k = get_s2k("PBKDF2(SHA-256)");
    s2k->set_iterations(4049);

    SecureVector<byte> key_and_IV = s2k->derive_key(48, passphrase).bits_of();
    SymmetricKey key(key_and_IV, 32);
    InitializationVector iv(key_and_IV + 32, 16);

    Encrypt(key, iv, filePlainText, fileEncrypted);



    return a.exec();
}

但是我在编译时遇到错误:

error: 'class Botan::PBKDF' has no member named 'set_iterations'
error: no matching function for call to 'Botan::PBKDF::derive_key(int, std::string&)'
...\_111-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\..\..\..\botan\include\botan\pbkdf.h:40: candidates are: virtual Botan::OctetString Botan::PBKDF::derive_key(size_t, const std::string&, const Botan::byte*, size_t, size_t) const

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

根据this similar question和文档,get_s2k()已被弃用,转而使用get_pbkdf()

我找不到最新的教程,但源代码包含新功能的示例。例如,来自doc/examples/encrypt.cpp的代码段

  std::auto_ptr<PBKDF> pbkdf(get_pbkdf("PBKDF2(SHA-1)"));

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

  const u32bit PBKDF2_ITERATIONS = 8192;

  SymmetricKey bc_key = pbkdf->derive_key(key_len, "BLK" + passphrase,
                                          &salt[0], salt.size(),
                                          PBKDF2_ITERATIONS);

  InitializationVector iv = pbkdf->derive_key(iv_len, "IVL" + passphrase,
                                              &salt[0], salt.size(),
                                              PBKDF2_ITERATIONS);

  SymmetricKey mac_key = pbkdf->derive_key(16, "MAC" + passphrase,
                                           &salt[0], salt.size(),
                                           PBKDF2_ITERATIONS);

还有其他例子。我认为源代码中的示例是最可靠的信息来源。