Fix Splitter between editor and viewer
This commit is contained in:
@@ -12,9 +12,6 @@ QJsonObject Note::toJson()
|
||||
o["uuid"] = this->uuid;
|
||||
o["title"] = this->title;
|
||||
o["content"] = this->content;
|
||||
#ifdef __SECURED
|
||||
o["encrypted"] = this->encrypted;
|
||||
#endif
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -46,43 +43,6 @@ QString Note::getContent()
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#ifdef __SECURED
|
||||
QString Note::getEncryptedContent(QString passwd)
|
||||
{
|
||||
if (this->encrypted)
|
||||
{
|
||||
using namespace CryptoPP;
|
||||
std::string password = passwd.toStdString();
|
||||
QString bytes = QByteArray::fromBase64(QByteArray::fromStdString(this->content.toStdString()));
|
||||
std::string encoded = bytes.toStdString();
|
||||
std::string iv = encoded.substr(0, TAG_SIZE);
|
||||
std::string cipher = encoded.substr(TAG_SIZE + 1, encoded.length());
|
||||
std::string recovered;
|
||||
|
||||
try {
|
||||
GCM< AES >::Decryption d;
|
||||
d.SetKeyWithIV((const unsigned char*)password.c_str(), sizeof(password.c_str()), (const unsigned char*)iv.c_str(), sizeof(iv.c_str()));
|
||||
|
||||
AuthenticatedDecryptionFilter df( d,
|
||||
new StringSink(recovered),
|
||||
AuthenticatedDecryptionFilter::DEFAULT_FLAGS, TAG_SIZE
|
||||
);
|
||||
StringSource ss2(cipher, true,
|
||||
new Redirector(df)
|
||||
);
|
||||
return QString::fromStdString(recovered);
|
||||
} catch (CryptoPP::Exception& e) {
|
||||
std::cout << e.GetWhat() << "\n";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool Note::isEncrypted()
|
||||
{
|
||||
return this->encrypted;
|
||||
}
|
||||
#endif
|
||||
void Note::setTitle(QString value)
|
||||
{
|
||||
this->title = value;
|
||||
@@ -94,53 +54,3 @@ void Note::setContent(QString value)
|
||||
this->content = value;
|
||||
}
|
||||
}
|
||||
#ifdef __SECURED
|
||||
// TODO encrypt avec le mot de passe
|
||||
bool Note::setEncryptedContent(QString value, QString passwd)
|
||||
{
|
||||
if (this->encrypted) {
|
||||
using namespace CryptoPP;
|
||||
AutoSeededRandomPool prng;
|
||||
std::string password = passwd.toStdString();
|
||||
std::string pdata = value.toStdString();
|
||||
std::string cipher, encoded;
|
||||
|
||||
SecByteBlock key(AES::MAX_KEYLENGTH + AES::BLOCKSIZE);
|
||||
SecByteBlock iv(AES::BLOCKSIZE);
|
||||
prng.GenerateBlock(iv, iv.size());
|
||||
try
|
||||
{
|
||||
GCM<AES>::Encryption e;
|
||||
e.SetKeyWithIV(key, sizeof(key), iv, sizeof(iv));
|
||||
|
||||
StringSource ss1(pdata, true,
|
||||
new AuthenticatedEncryptionFilter(e,
|
||||
new StringSink(cipher), false, TAG_SIZE
|
||||
)
|
||||
);
|
||||
std::string s(reinterpret_cast< char const* >(iv.data())) ;
|
||||
encoded = s + cipher;
|
||||
auto bytes = QByteArray::fromStdString(encoded);
|
||||
this->content = bytes.toBase64();
|
||||
return true;
|
||||
}
|
||||
catch(CryptoPP::Exception& e)
|
||||
{
|
||||
std::cout << e.GetWhat() << "\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Note::encrypt(QString password)
|
||||
{
|
||||
if (!this->encrypted && (password.length() >= 6)) {
|
||||
this->encrypted = true;
|
||||
if (!setEncryptedContent(this->content, password))
|
||||
{
|
||||
this->encrypted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -11,18 +11,6 @@
|
||||
#include <QUuid>
|
||||
#include <QMessageBox>
|
||||
|
||||
#ifdef __SECURED
|
||||
#include <crypto++/modes.h>
|
||||
#include <crypto++/aes.h>
|
||||
#include <crypto++/filters.h>
|
||||
#include <crypto++/cryptlib.h>
|
||||
#include <crypto++/sha.h>
|
||||
#include <crypto++/hkdf.h>
|
||||
#include <crypto++/osrng.h>
|
||||
#include <crypto++/gcm.h>
|
||||
#include <crypto++/rijndael.h>
|
||||
#endif
|
||||
|
||||
class Note
|
||||
{
|
||||
public:
|
||||
@@ -35,18 +23,8 @@ public:
|
||||
QString getTitle();
|
||||
QString getContent();
|
||||
|
||||
#ifdef __SECURED
|
||||
QString getEncryptedContent(QString passwd);
|
||||
bool isEncrypted();
|
||||
#endif
|
||||
|
||||
void setTitle(QString value);
|
||||
void setContent(QString value);
|
||||
|
||||
#ifdef __SECURED
|
||||
bool setEncryptedContent(QString value, QString passwd);
|
||||
void encrypt(QString password);
|
||||
#endif
|
||||
private:
|
||||
QString uuid;
|
||||
QString title;
|
||||
|
||||
Reference in New Issue
Block a user