Dokończona funkcja generowania pliku HPP która przechowuje array z kluczem deszyfrującym
This commit is contained in:
parent
967e1e9c13
commit
c234825ac5
4 changed files with 41 additions and 5 deletions
|
|
@ -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<unsigned char> keyVec(key.begin(), key.end());
|
||||
std::vector<unsigned char> nonceVec(nonce.begin(), nonce.end());
|
||||
|
||||
const std::string headerText =
|
||||
"// Plik wygenerowany przy wykorzystaniu exPAK\n\n"
|
||||
"// Klucz deszyfruj¹cy\n"
|
||||
"const std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{};\n\n"
|
||||
"const std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{" + toHex(keyVec) + "};\n\n"
|
||||
"// Ci¹g nonce\n"
|
||||
"const std::array<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{};";
|
||||
"const std::array<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{" + toHex(nonceVec) + "}; ";
|
||||
|
||||
std::ofstream file(path + ".hpp");
|
||||
file << headerText;
|
||||
file.close();
|
||||
}
|
||||
|
||||
std::string EncryptionManager::toHex(const std::vector<unsigned char>& 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<int>(b);
|
||||
|
||||
bytes += "'";
|
||||
bytes += ss.str();
|
||||
bytes += "'";
|
||||
|
||||
if (skp < sk)
|
||||
{
|
||||
bytes += ", ";
|
||||
skp++;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Wczytaj klucz
|
||||
void EncryptionManager::loadKey(const std::string& path)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,10 @@
|
|||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <xxhash.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <algorithm>
|
||||
|
||||
#include "DataStruct.h"
|
||||
|
||||
class EncryptionManager
|
||||
|
|
@ -28,5 +32,6 @@ private:
|
|||
bool keyReady;
|
||||
|
||||
void generateKeys();
|
||||
std::string toHex(const std::vector<unsigned char>&);
|
||||
void saveCppHeadFile(const std::string&);
|
||||
};
|
||||
6
test.hpp
6
test.hpp
|
|
@ -1,5 +1,7 @@
|
|||
// Plik wygenerowany przy wykorzystaniu exPAK
|
||||
|
||||
const std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> key{};
|
||||
// Klucz deszyfruj¹cy
|
||||
const std::array<unsigned char, crypto_stream_chacha20_ietf_KEYBYTES> 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<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{};
|
||||
// Ci¹g nonce
|
||||
const std::array<unsigned char, crypto_stream_chacha20_ietf_NONCEBYTES> nonce{'0x5E', '0x8F', '0x8B', '0x17', '0x16', '0xE3', '0xDB', '0xE0', '0xBF', '0xF0', '0x25', '0xDA'};
|
||||
BIN
test.key
BIN
test.key
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue