mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
add decryption
This commit is contained in:
parent
63bb51a089
commit
71e42cf6c8
44
src/core.cpp
44
src/core.cpp
|
@ -1070,6 +1070,8 @@ bool Core::loadConfiguration()
|
||||||
qWarning() << "Core: tox_load failed with error "<<error;
|
qWarning() << "Core: tox_load failed with error "<<error;
|
||||||
}
|
}
|
||||||
else if (error == 1) // Encrypted data save
|
else if (error == 1) // Encrypted data save
|
||||||
|
{
|
||||||
|
if (!pwhash)
|
||||||
{
|
{
|
||||||
qWarning() << "Core: Can not open encrypted tox save";
|
qWarning() << "Core: Can not open encrypted tox save";
|
||||||
if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"),
|
if (QMessageBox::Ok != QMessageBox::warning(nullptr, tr("Encrypted profile"),
|
||||||
|
@ -1081,6 +1083,15 @@ bool Core::loadConfiguration()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{ /*
|
||||||
|
while (error != 0)
|
||||||
|
{
|
||||||
|
error = tox_encrypted_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size(), pwhash, TOX_HASH_LENGTH);
|
||||||
|
// something something QInputDialog new password
|
||||||
|
} */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configurationFile.close();
|
configurationFile.close();
|
||||||
|
@ -1467,6 +1478,20 @@ QByteArray Core::encryptData(const QByteArray& data)
|
||||||
return QByteArray(reinterpret_cast<char*>(encrypted), data.size() + tox_pass_encryption_extra_length());
|
return QByteArray(reinterpret_cast<char*>(encrypted), data.size() + tox_pass_encryption_extra_length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray Core::decryptData(const QByteArray& data)
|
||||||
|
{
|
||||||
|
if (!pwhash)
|
||||||
|
return QByteArray();
|
||||||
|
int sz = data.size() - tox_pass_encryption_extra_length();
|
||||||
|
uint8_t decrypted[sz];
|
||||||
|
if (tox_pass_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), pwhash, TOX_HASH_LENGTH, decrypted) != sz)
|
||||||
|
{
|
||||||
|
qWarning() << "Core::decryptData: decryption failed";
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
return QByteArray(reinterpret_cast<char*>(decrypted), sz);
|
||||||
|
}
|
||||||
|
|
||||||
bool Core::encryptFile(const QString& path)
|
bool Core::encryptFile(const QString& path)
|
||||||
{
|
{
|
||||||
if (!pwhash)
|
if (!pwhash)
|
||||||
|
@ -1495,3 +1520,22 @@ bool Core::encryptFile(const QString& path)
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QByteArray Core::decryptFile(const QString& path)
|
||||||
|
{
|
||||||
|
if (!pwhash)
|
||||||
|
return QByteArray();
|
||||||
|
QFile file(path);
|
||||||
|
if (!file.exists()) {
|
||||||
|
qWarning() << "Core::decryptFile: file" << path << "DNE";
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
qCritical() << "Core::decryptFile:" << path << " cannot be opened";
|
||||||
|
return QByteArray();
|
||||||
|
}
|
||||||
|
QByteArray data = file.readAll();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return decryptData(data);
|
||||||
|
}
|
||||||
|
|
|
@ -98,6 +98,8 @@ public slots:
|
||||||
void clearPassword();
|
void clearPassword();
|
||||||
bool encryptFile(const QString& path);
|
bool encryptFile(const QString& path);
|
||||||
QByteArray encryptData(const QByteArray& data);
|
QByteArray encryptData(const QByteArray& data);
|
||||||
|
QByteArray decryptData(const QByteArray& data);
|
||||||
|
QByteArray decryptFile(const QString& path);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connected();
|
void connected();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user