UTPassMirror/plugins/Pass/pass.cpp

59 lines
1.8 KiB
C++
Raw Normal View History

2019-03-13 18:38:12 +00:00
#include <QDebug>
2019-03-15 16:53:40 +00:00
#include <QFile>
2019-03-13 18:38:12 +00:00
#include "pass.h"
2019-03-15 16:53:40 +00:00
#include "gpgme++/global.h"
#include "qgpgme/protocol.h"
#include "qgpgme/encryptjob.h"
#include "qgpgme/decryptjob.h"
#include "qgpgme/keylistjob.h"
2019-03-13 18:38:12 +00:00
Pass::Pass() {
2019-03-15 16:53:40 +00:00
GpgME::initializeLibrary();
this->gpgHome = qgetenv("GNUPGHOME");
}
QString Pass::decrypt(const QByteArray cipherText) {
/*auto decJob = QGpgME::openpgp()->decryptJob();
auto ctx = QGpgME::Job::context(decJob);
TestPassphraseProvider provider;
ctx->setPassphraseProvider(&provider);
ctx->setPinentryMode(Context::PinentryLoopback);
2019-03-13 18:38:12 +00:00
2019-03-15 16:53:40 +00:00
QByteArray plainText;
decJob->exec(cipherText, plainText);
return QString::fromUtf8(plainText);*/
2019-03-13 18:38:12 +00:00
}
2019-03-15 16:53:40 +00:00
QString Pass::decrypt_file(const QString path) {
/*QFile file(path);
if (!file.open(QIODevice::ReadOnly)) {
qErrnoWarning("Can't open the File");
return nullptr;
2019-03-13 18:38:12 +00:00
}
2019-03-15 16:53:40 +00:00
QByteArray plainText = file.readAll();
return Pass::decrypt(plainText);*/
2019-03-13 18:38:12 +00:00
}
2019-03-15 16:53:40 +00:00
QByteArray Pass::encrypt(const QString str) {
/*auto listjob = QGpgME::openpgp()->keyListJob(false, false, false);
std::vector<GpgME::Key> keys;
auto keylistresult = listjob->exec(QStringList() << QStringLiteral("alfa@example.net"),
false, keys);
auto job = QGpgME::openpgp()->encryptJob(/*ASCII Armor *//*true, /* Textmode *//* true);
QByteArray cipherText;
auto result = job->exec(keys, QStringLiteral("Hello World").toUtf8(), GpgME::Context::AlwaysTrust, cipherText);
return cipherText;*/
}
2019-03-13 18:38:12 +00:00
2019-03-15 16:53:40 +00:00
bool Pass::encrypt_file(const QString str, const QString path) {
/*QFile file(path);
if (!file.open(QIODevice::WriteOnly)) {
qErrnoWarning("Can't open the File");
return false;
}
file.write(Pass::encrypt(str));
return true;*/
2019-03-13 18:38:12 +00:00
}