2023-02-20 15:10:57 +00:00
|
|
|
#include "qcipher.h"
|
|
|
|
|
|
|
|
QCipher::QCipher(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
c = Cipher("aes-256-cbc", "sha256");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString QCipher::encrypt(QString plaintext, QString pass)
|
|
|
|
{
|
2023-02-20 15:48:52 +00:00
|
|
|
try {
|
|
|
|
std::string enc;
|
|
|
|
enc = c.encrypt(plaintext.toStdString(), pass.toStdString());
|
|
|
|
return QString::fromUtf8(enc.c_str());
|
|
|
|
} catch (...) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-02-20 15:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QCipher::decrypt(QString ciphertext, QString pass)
|
|
|
|
{
|
2023-02-20 15:48:52 +00:00
|
|
|
try {
|
|
|
|
std::string dec;
|
|
|
|
dec = c.decrypt(ciphertext.toStdString(), pass.toStdString());
|
|
|
|
return QString::fromUtf8(dec.c_str());
|
|
|
|
} catch (...) {
|
|
|
|
return "";
|
|
|
|
}
|
2023-02-20 15:10:57 +00:00
|
|
|
};
|