I need to build something that is not very complicated, but efficient. I don't have much time to debug.
I don't know if this method is strong enough to encrypt a data to be displayed in a Qr code.
It will be compiled in Qt.
#include <botan/botan.h>
#include <botan/aes.h>
#include <botan/kdf.h>
#include <botan/pbkdf2.h>
#include <botan/hmac.h>
#include <botan/sha160.h>
using namespace std;
using namespace Botan;
// .....
bool BotanWrapper::EncryptFile(QString Source, QString Destination)
{
try
{
//Setup the key derive functions
PKCS5_PBKDF2 pbkdf2(new HMAC(new SHA_160));
const u32bit PBKDF2_ITERATIONS = 8192;
//Create the KEY and IV
KDF* kdf = get_kdf("KDF2(SHA-1)");
//Create the master key
SecureVector<byte> mMaster = pbkdf2.derive_key(48, mPassword.toStdString(), &mSalt[0], mSalt.size(),PBKDF2_ITERATIONS).bits_of();
SymmetricKey mKey = kdf->derive_key(32, mMaster, "salt1");
InitializationVector mIV = kdf->derive_key(16, mMaster, "salt2");
string inFilename = Source.toStdString();
string outFilename = Destination.toStdString();
std::ifstream in(inFilename.c_str(),std::ios::binary);
std::ofstream out(outFilename.c_str(),std::ios::binary);
Pipe pipe(get_cipher("AES-256/CBC/PKCS7", mKey, mIV,ENCRYPTION),new DataSink_Stream(out));
pipe.start_msg();
in >> pipe;
pipe.end_msg();
out.flush();
out.close();
in.close();
return true;
}
catch(...)
{
return false;
}
}