diff --git a/src/core/core.cpp b/src/core/core.cpp index 42f6f4d4d..d6358a613 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -870,11 +870,14 @@ QPair Core::getKeypair() const if (!tox) return keypair; - char buf[std::max(TOX_PUBLIC_KEY_SIZE, TOX_SECRET_KEY_SIZE)]; - tox_self_get_public_key(tox, (uint8_t*)buf); - keypair.first = QByteArray(buf, TOX_PUBLIC_KEY_SIZE); - tox_self_get_secret_key(tox, (uint8_t*)buf); - keypair.second = QByteArray(buf, TOX_SECRET_KEY_SIZE); + QByteArray pk(TOX_PUBLIC_KEY_SIZE, 0x00); + QByteArray sk(TOX_SECRET_KEY_SIZE, 0x00); + + tox_self_get_public_key(tox, (uint8_t*) pk.data()); + tox_self_get_secret_key(tox, (uint8_t*) sk.data()); + + keypair.first = pk; + keypair.second = sk; return keypair; } diff --git a/src/core/coreencryption.cpp b/src/core/coreencryption.cpp index 7581ce413..5e9c32051 100644 --- a/src/core/coreencryption.cpp +++ b/src/core/coreencryption.cpp @@ -64,14 +64,14 @@ QByteArray Core::encryptData(const QByteArray &data) QByteArray Core::encryptData(const QByteArray& data, const Tox_Pass_Key& encryptionKey) { - uint8_t encrypted[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; + QByteArray encrypted(data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, 0x00); if (!tox_pass_key_encrypt(&encryptionKey, reinterpret_cast(data.data()), data.size(), - encrypted, nullptr)) + (uint8_t*) encrypted.data(), nullptr)) { qWarning() << "Encryption failed"; return QByteArray(); } - return QByteArray(reinterpret_cast(encrypted), data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH); + return encrypted; } /** @@ -89,18 +89,18 @@ QByteArray Core::decryptData(const QByteArray& data, const Tox_Pass_Key& encrypt { if (data.size() < TOX_PASS_ENCRYPTION_EXTRA_LENGTH) { - qWarning() << "Not enough data:"<(data.data()), data.size(), - decrypted, nullptr)) + (uint8_t*) decrypted.data(), nullptr)) { qWarning() << "Decryption failed"; return QByteArray(); } - return QByteArray(reinterpret_cast(decrypted), sz); + return decrypted; } QByteArray Core::getSaltFromFile(QString filename)