aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Fella <fella@posteo.de>2022-02-13 22:11:52 +0100
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-02-16 17:58:17 +0100
commit445e34f26450cf8262a65b74e1294579d9cd56be (patch)
tree0e9c8df86fca769313817531eb4f94f2abed829f
parent0f6506c022ff1ccaa648ff50b81ae29f5a6f2176 (diff)
downloadlibquotient-445e34f26450cf8262a65b74e1294579d9cd56be.tar.gz
libquotient-445e34f26450cf8262a65b74e1294579d9cd56be.zip
Fix file decryption
-rw-r--r--lib/events/encryptedfile.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/events/encryptedfile.cpp b/lib/events/encryptedfile.cpp
index 74119127..dbb72af8 100644
--- a/lib/events/encryptedfile.cpp
+++ b/lib/events/encryptedfile.cpp
@@ -13,7 +13,7 @@ using namespace Quotient;
QByteArray EncryptedFile::decryptFile(const QByteArray &ciphertext) const
{
QString _key = key.k;
- _key = QByteArray::fromBase64(_key.replace(QLatin1Char('_'), QLatin1Char('/')).replace(QLatin1Char('-'), QLatin1Char('+')).toLatin1());
+ auto keyBytes = QByteArray::fromBase64(_key.replace(QLatin1Char('_'), QLatin1Char('/')).replace(QLatin1Char('-'), QLatin1Char('+')).toLatin1());
const auto sha256 = QByteArray::fromBase64(hashes["sha256"].toLatin1());
if(sha256 != QCryptographicHash::hash(ciphertext, QCryptographicHash::Sha256)) {
qCWarning(E2EE) << "Hash verification failed for file";
@@ -23,7 +23,7 @@ QByteArray EncryptedFile::decryptFile(const QByteArray &ciphertext) const
EVP_CIPHER_CTX *ctx;
int length;
ctx = EVP_CIPHER_CTX_new();
- EVP_DecryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, (const unsigned char *)_key.data(), (const unsigned char *)iv.toLatin1().data());
+ EVP_DecryptInit_ex(ctx, EVP_aes_256_ctr(), NULL, (const unsigned char *)keyBytes.data(), (const unsigned char *)QByteArray::fromBase64(iv.toLatin1()).data());
EVP_DecryptUpdate(ctx, (unsigned char *)plaintext.data(), &length, (const unsigned char *)ciphertext.data(), ciphertext.size());
EVP_DecryptFinal_ex(ctx, (unsigned char *)plaintext.data() + length, &length);
EVP_CIPHER_CTX_free(ctx);