Wstępnie dodana klasa zarządzania szyfrowaniem. Dodana funckja szyfrująca i generowanie kluczy. Nie osadzono w klasie create cargo
This commit is contained in:
parent
de7ced2939
commit
b80d983bc7
6 changed files with 67 additions and 14 deletions
28
EncryptionManager.cpp
Normal file
28
EncryptionManager.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "EncryptionManager.h"
|
||||
|
||||
EncryptionManager::EncryptionManager()
|
||||
{
|
||||
if (sodium_init() < 0) {
|
||||
throw std::runtime_error("libsodium init failed");
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
||||
{
|
||||
randombytes_buf(key.data(), key.size());
|
||||
randombytes_buf(nonce.data(), nonce.size());
|
||||
|
||||
std::vector<char> crypt(raw.size());
|
||||
|
||||
if (crypto_stream_chacha20_ietf_xor_ic(
|
||||
reinterpret_cast<unsigned char*>(crypt.data()),
|
||||
reinterpret_cast<const unsigned char*>(raw.data()),
|
||||
static_cast<unsigned long long>(raw.size()),
|
||||
nonce.data(),
|
||||
0,
|
||||
key.data()) != 0) {
|
||||
throw std::runtime_error("crypto_stream_chacha20_ietf_xor_ic failed");
|
||||
}
|
||||
|
||||
return crypt;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue