Naprawiono problem z nie grenerowaniem klucza szyfrującego
This commit is contained in:
parent
29b2460910
commit
fd42a5812a
8 changed files with 23 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -381,3 +381,4 @@ test8/
|
|||
test9/
|
||||
test10/
|
||||
testx/
|
||||
testv/
|
||||
|
|
@ -13,7 +13,7 @@ ChunkManager::~ChunkManager()
|
|||
// Dzielenie vectora na chunki dokładnie po 128KB
|
||||
// Kompresowanie chunków bez nagłówka
|
||||
//-----------------------------------------------------------------------------
|
||||
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& encrypt)
|
||||
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& compress, const bool& encrypt)
|
||||
{
|
||||
//std::vector<BlockSize> blockSizes;
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ std::vector<char> ChunkManager::compress_data(const std::vector<char>& input)
|
|||
//-----------------------------------------------------------------------------
|
||||
// Dekompresja blokowa
|
||||
//-----------------------------------------------------------------------------
|
||||
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& encrypt)
|
||||
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& compress, const bool& encrypt)
|
||||
{
|
||||
size_t offset = 0;
|
||||
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ public:
|
|||
~ChunkManager();
|
||||
|
||||
// Kompresja danych
|
||||
std::vector<char> chunked(const std::vector<char>&, const bool&);
|
||||
std::vector<char> chunked(const std::vector<char>&, const bool&, const bool&);
|
||||
|
||||
// Dekompresja
|
||||
std::vector<char> dechunked(const std::vector<char>&, const bool&);
|
||||
std::vector<char> dechunked(const std::vector<char>&, const bool&, const bool&);
|
||||
|
||||
private:
|
||||
EncryptionManager eman;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ CreateCargo::CreateCargo()
|
|||
, version(VERSION)
|
||||
, methodFlags(0)
|
||||
, offset(0)
|
||||
, hppKey(false)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
|
@ -87,9 +88,9 @@ bool CreateCargo::Create(const std::string& path, const int16_t& flag)
|
|||
}
|
||||
|
||||
// Zapisywanie klucza szyfruj¹cego
|
||||
if (flag == 2 || flag == 3)
|
||||
if (flag == 2 || flag == 3 || encList.size() > 0)
|
||||
{
|
||||
crypt.saveKey(catalogPath);
|
||||
crypt.saveKey(catalogPath, hppKey);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -194,15 +195,15 @@ void CreateCargo::computingBytes(const int16_t& flag, std::vector<char>& input,
|
|||
switch (flag)
|
||||
{
|
||||
case 1:
|
||||
output = cm.chunked(input, false);
|
||||
output = cm.chunked(input, true, false);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
output = crypt.encrypt(input);
|
||||
output = cm.chunked(input, false, true);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
output = crypt.encrypt(cm.chunked(input, false));
|
||||
output = cm.chunked(input, true, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -287,6 +288,8 @@ void CreateCargo::GetFilters(const std::string& filterFile)
|
|||
|
||||
// Lista plików do pominiêcia
|
||||
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
|
||||
|
||||
hppKey = jslist["keyhpp"];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ private:
|
|||
std::vector<std::string> filesList;
|
||||
|
||||
EncryptionManager crypt;
|
||||
bool hppKey;
|
||||
|
||||
// listy wyj¹tków
|
||||
std::vector<std::string> ignoreList;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ EncryptionManager::EncryptionManager()
|
|||
}
|
||||
|
||||
keyReady = false;
|
||||
generateKeys();
|
||||
}
|
||||
|
||||
std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
||||
|
|
@ -15,7 +16,7 @@ std::vector<char> EncryptionManager::encrypt(const std::vector<char>& raw)
|
|||
std::vector<char> crypt(raw.size());
|
||||
|
||||
// Generowanie kluczy
|
||||
generateKeys();
|
||||
// generateKeys();
|
||||
|
||||
if (crypto_stream_chacha20_ietf_xor_ic(
|
||||
reinterpret_cast<unsigned char*>(crypt.data()),
|
||||
|
|
@ -40,7 +41,7 @@ void EncryptionManager::generateKeys()
|
|||
keyReady = true;
|
||||
}
|
||||
|
||||
void EncryptionManager::saveKey(const std::string& path)
|
||||
void EncryptionManager::saveKey(const std::string& path, bool hpp)
|
||||
{
|
||||
const int sig = SIGNATURE_KEY_FILE;
|
||||
const short ver = VERSION;
|
||||
|
|
@ -73,7 +74,7 @@ void EncryptionManager::saveKey(const std::string& path)
|
|||
|
||||
file.close();
|
||||
|
||||
//saveCppHeadFile(path);
|
||||
if (hpp) {saveCppHeadFile(path);}
|
||||
}
|
||||
|
||||
// Generowanie pliku nag³ówkowego CPP z kluczem i nonce
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public:
|
|||
std::vector<char> encrypt(const std::vector<char>&);
|
||||
std::vector<char> decrypt(const std::vector<char>&);
|
||||
|
||||
void saveKey(const std::string&);
|
||||
void saveKey(const std::string&, bool);
|
||||
void loadKey(const std::string&);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -144,15 +144,15 @@ void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<ch
|
|||
switch (flag)
|
||||
{
|
||||
case 1:
|
||||
output = cm.dechunked(input, false);
|
||||
output = cm.dechunked(input, true, false);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
output = eman.decrypt(input);
|
||||
output = cm.dechunked(input, false, true);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
output = cm.dechunked(input, false);
|
||||
output = cm.dechunked(input, true, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue