I've tried to encrypt file using Botan library, and coded the following:
#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();
}
But I get an error while compiling:
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
How can I fix this?
According to this similar question and the documentation,
get_s2k()
has been deprecated in favour ofget_pbkdf()
.I could not find an up-to-date tutorial, but the source code contains examples for the new function. For example, a snippet from
doc/examples/encrypt.cpp
:There are other examples, too. I think the examples from the source code are the most reliable sources of information.