diff --git a/EncryptionManager.cpp b/EncryptionManager.cpp index 415d54a..98cb0da 100644 --- a/EncryptionManager.cpp +++ b/EncryptionManager.cpp @@ -80,20 +80,49 @@ void EncryptionManager::saveKey(const std::string& path) // Generowanie pliku nagłówkowego CPP z kluczem i nonce void EncryptionManager::saveCppHeadFile(const std::string& path) { + std::vector keyVec(key.begin(), key.end()); + std::vector nonceVec(nonce.begin(), nonce.end()); + const std::string headerText = "// Plik wygenerowany przy wykorzystaniu exPAK\n\n" "// Klucz deszyfrujący\n" - "const std::array key{};\n\n" + "const std::array key{" + toHex(keyVec) + "};\n\n" "// Ciąg nonce\n" - "const std::array nonce{};"; + "const std::array nonce{" + toHex(nonceVec) + "}; "; std::ofstream file(path + ".hpp"); file << headerText; file.close(); } +std::string EncryptionManager::toHex(const std::vector& data) +{ + std::string bytes; + int sk = data.size(); + int skp = 1; + + for (const auto& b : data) + { + std::stringstream ss; + ss << "0x" << std::hex << std::uppercase << std::setw(2) << std::setfill('0') + << static_cast(b); + + bytes += "'"; + bytes += ss.str(); + bytes += "'"; + + if (skp < sk) + { + bytes += ", "; + skp++; + } + } + + return bytes; +} + // Wczytaj klucz void EncryptionManager::loadKey(const std::string& path) { - + } \ No newline at end of file diff --git a/EncryptionManager.h b/EncryptionManager.h index aa4e7ab..fad298d 100644 --- a/EncryptionManager.h +++ b/EncryptionManager.h @@ -8,6 +8,10 @@ #include #include #include +#include +#include +#include + #include "DataStruct.h" class EncryptionManager @@ -28,5 +32,6 @@ private: bool keyReady; void generateKeys(); + std::string toHex(const std::vector&); void saveCppHeadFile(const std::string&); }; \ No newline at end of file diff --git a/test.hpp b/test.hpp index 0751f98..0ac6d06 100644 --- a/test.hpp +++ b/test.hpp @@ -1,5 +1,7 @@ // Plik wygenerowany przy wykorzystaniu exPAK -const std::array key{}; +// Klucz deszyfrujący +const std::array key{'0xBB', '0xEF', '0x33', '0xD0', '0x9F', '0xB2', '0xAB', '0x54', '0xD3', '0xF2', '0xDA', '0xF7', '0x51', '0x5B', '0x67', '0x8C', '0xA4', '0xAA', '0xF1', '0xC0', '0x14', '0x81', '0x8C', '0x23', '0x86', '0x06', '0xBC', '0x1E', '0xE6', '0x49', '0xF1', '0xE0'}; -const std::array nonce{}; \ No newline at end of file +// Ciąg nonce +const std::array nonce{'0x5E', '0x8F', '0x8B', '0x17', '0x16', '0xE3', '0xDB', '0xE0', '0xBF', '0xF0', '0x25', '0xDA'}; \ No newline at end of file diff --git a/test.key b/test.key index ca8b832..552c171 100644 Binary files a/test.key and b/test.key differ