From b80d983bc74fa5f9d228f26f8addcce4535ef352 Mon Sep 17 00:00:00 2001 From: yanczi Date: Sun, 26 Oct 2025 01:14:55 +0200 Subject: [PATCH] =?UTF-8?q?Wst=C4=99pnie=20dodana=20klasa=20zarz=C4=85dzan?= =?UTF-8?q?ia=20szyfrowaniem.=20Dodana=20funckja=20szyfruj=C4=85ca=20i=20g?= =?UTF-8?q?enerowanie=20kluczy.=20Nie=20osadzono=20w=20klasie=20create=20c?= =?UTF-8?q?argo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CreateCargo.h | 3 ++- EncryptionManager.cpp | 28 ++++++++++++++++++++++++++++ EncryptionManager.h | 20 ++++++++++++++++++++ voidcmd.cpp | 4 +++- voidcmd.vcxproj | 14 ++++++++------ voidcmd.vcxproj.filters | 12 ++++++------ 6 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 EncryptionManager.cpp create mode 100644 EncryptionManager.h diff --git a/CreateCargo.h b/CreateCargo.h index ddf0967..edacd6f 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -36,6 +36,7 @@ #include "Txtpp.h" #include "xxhash.h" #include "CompressingManager.h" +#include "EncryptionManager.h" @@ -72,7 +73,7 @@ private: std::vector filesList; - + EncryptionManager crypt; // listy wyj箃k體 std::vector ignoreList; diff --git a/EncryptionManager.cpp b/EncryptionManager.cpp new file mode 100644 index 0000000..eac5e5a --- /dev/null +++ b/EncryptionManager.cpp @@ -0,0 +1,28 @@ +#include "EncryptionManager.h" + +EncryptionManager::EncryptionManager() +{ + if (sodium_init() < 0) { + throw std::runtime_error("libsodium init failed"); + } +} + +std::vector EncryptionManager::encrypt(const std::vector& raw) +{ + randombytes_buf(key.data(), key.size()); + randombytes_buf(nonce.data(), nonce.size()); + + std::vector crypt(raw.size()); + + if (crypto_stream_chacha20_ietf_xor_ic( + reinterpret_cast(crypt.data()), + reinterpret_cast(raw.data()), + static_cast(raw.size()), + nonce.data(), + 0, + key.data()) != 0) { + throw std::runtime_error("crypto_stream_chacha20_ietf_xor_ic failed"); + } + + return crypt; +} \ No newline at end of file diff --git a/EncryptionManager.h b/EncryptionManager.h new file mode 100644 index 0000000..79fe7f4 --- /dev/null +++ b/EncryptionManager.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include +#include + +class EncryptionManager +{ +public: + EncryptionManager(); + ~EncryptionManager() = default; + + std::vector encrypt(const std::vector&); + //std::vector decrypt(const std::vector&); + +private: + std::array key{}; + std::array nonce{}; +}; \ No newline at end of file diff --git a/voidcmd.cpp b/voidcmd.cpp index bd326ff..ba2147b 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -44,6 +44,8 @@ void RenderHelp() " -p Pack files from the specified directory \n" " -e Pack and encrypted from the specified directory \n" " -f Pack the files according to the guidelines given in the .txt \n" + " -s Pack and encrypted \n" + " -cs Pack and compress \n" " \n" "Extracting: \n" " -x Extract files from the specified container \n" @@ -55,7 +57,7 @@ void RenderHelp() "Keys: \n" " \n" " {compress} - Compressing files \n" - " {crypt} - Encrypted files with AES256 \n" + " {crypt} - Encrypted files with ChaCha20 \n" " {ignore} - Ignoring concrete files \n" " \n" " /path/to/file.ext - Concrete file \n" diff --git a/voidcmd.vcxproj b/voidcmd.vcxproj index 35415ae..b3a2f71 100644 --- a/voidcmd.vcxproj +++ b/voidcmd.vcxproj @@ -104,13 +104,13 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\crc\include;3rd\ftxui\include;3rd\lz4\include + 3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include Console true - 3rd\ftxui\Debug;3rd\lz4\lib - liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib + 3rd\ftxui\Debug;3rd\lz4\lib;3rd\libsodium\lib\Debug + liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib @@ -122,18 +122,19 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\crc\include;3rd\ftxui\include;3rd\lz4\include + 3rd\crc\include;3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include Console true - 3rd\ftxui\Release;3rd\lz4\lib - liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib + 3rd\libsodium\lib\Release;3rd\ftxui\Release;3rd\lz4\lib + liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib + @@ -143,6 +144,7 @@ + diff --git a/voidcmd.vcxproj.filters b/voidcmd.vcxproj.filters index b2edffa..7752806 100644 --- a/voidcmd.vcxproj.filters +++ b/voidcmd.vcxproj.filters @@ -27,15 +27,15 @@ Pliki 藕r贸d艂owe - - Pliki 藕r贸d艂owe - Pliki 藕r贸d艂owe Pliki 藕r贸d艂owe + + Pliki 藕r贸d艂owe + @@ -53,15 +53,15 @@ Pliki nag艂贸wkowe - - Pliki nag艂贸wkowe - Pliki nag艂贸wkowe Pliki nag艂贸wkowe + + Pliki nag艂贸wkowe +