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)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue