MCPcopy Create free account
hub / github.com/LANDrop/LANDrop / decrypt

Method decrypt

LANDrop/crypto.cpp:96–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96QByteArray Crypto::decrypt(const QByteArray &data)
97{
98 if (static_cast<quint64>(data.size()) < crypto_aead_chacha20poly1305_IETF_NPUBBYTES)
99 throw std::runtime_error(tr("Cipher text too short.").toUtf8().toStdString());
100 QByteArray plainText(data.size() - crypto_aead_chacha20poly1305_IETF_ABYTES, 0);
101 quint64 plainTextLen;
102 QByteArray nonce = data.left(crypto_aead_chacha20poly1305_IETF_NPUBBYTES);
103 QByteArray cipherText = data.mid(crypto_aead_chacha20poly1305_IETF_NPUBBYTES);
104 if (crypto_aead_chacha20poly1305_ietf_decrypt(reinterpret_cast<unsigned char *>(plainText.data()), &plainTextLen,
105 nullptr,
106 reinterpret_cast<const unsigned char *>(cipherText.data()), cipherText.size(),
107 nullptr, 0,
108 reinterpret_cast<const unsigned char *>(nonce.data()),
109 reinterpret_cast<const unsigned char *>(sessionKey.data())) != 0)
110 throw std::runtime_error(tr("Decryption failed.").toUtf8().toStdString());
111 return plainText.left(plainTextLen);
112}
113
114void Crypto::init()
115{

Callers 1

socketReadyReadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected