Tenho seguinte código c++ std::vector<uint8_t> EncryptionKey = { 0x8c, 0x6e, 0x58, 0x84,…
- User
Tenho seguinte código c++
std::vector<uint8_t> EncryptionKey = { 0x8c, 0x6e, 0x58, 0x84, 0x2d, 0x37, 0x26, 0x67, 0x72, 0x4b, 0x0d, 0x10, 0x3f, 0x26, 0x3b, 0xe8, 0x2b, 0xa3, 0x60, 0xd0, 0x0d, 0xde, 0x88, 0x5c, 0x60, 0x27, 0xf9, 0x81, 0xa6, 0x2c, 0xa8, 0xcd, 0xa0, 0xa9, 0x28, 0x64, 0xe3, 0x17, 0xf6, 0xc5, 0x16, 0x98, 0xcc, 0x96, 0xae, 0x38, 0x2e, 0x2b, 0x55, 0x96, 0x22, 0x5b, 0xb5, 0xb5, 0x21, 0xf6, 0xc8, 0xf7, 0xc5, 0x95, 0xf2, 0x85, 0x81, 0x54, 0x2f, 0x34, 0x82, 0x3a, 0x6a, 0x6f, 0xd3, 0x5d, 0xb7, 0xed, 0x53, 0xb8, 0x7e, 0x52, 0x04, 0x57, 0x5c, 0x81, 0x59, 0x9b, 0x7b, 0xca, 0xbd, 0x30, 0x4c, 0xe2, 0x37, 0xc5, 0x58, 0x66, 0x71, 0x43, 0xae, 0x21, 0x15, 0x86, 0x13, 0xec, 0x6e, 0xeb, 0x96, 0x85, 0x55, 0xfa, 0x3c, 0x11, 0xc4, 0x50, 0xdb, 0xe8, 0x94, 0xf7, 0xe0, 0xd1, 0x2f, 0x8f, 0x3b, 0xa8, 0x90, 0x26, 0xed, 0x37, 0x93, 0xf8, 0x78, 0x61, 0x17, 0x9b, 0xf9, 0x52, 0x81, 0x54, 0x98, 0x3e, 0x36, 0x19, 0xc0, 0x68, 0x22, 0xed, 0x52, 0x65, 0xe9, 0xdd, 0x2d, 0x2b, 0x57, 0xef, 0xd6, 0x2b, 0x95, 0x44, 0x5e, 0xbe, 0x14, 0x61, 0x51, 0x7d, 0xa9, 0x9b, 0xa5, 0x03, 0x7e, 0xcc, 0xe2, 0xa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0x36, 0x9d, 0x3d, 0x5b, 0xf4, 0x6b, 0x49, 0x8b, 0xf0, 0xfe, 0x80, 0xe9, 0xc9, 0x5b, 0xc5, 0xac, 0x72, 0x3f, 0x22, 0x5e };
CryptoPP::SecByteBlock DeriveKeyFromPassword(const std::string& password, const byte* salt, size_t saltSize) { CryptoPP::SecByteBlock key(CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::PKCS5_PBKDF2_HMAC<CryptoPP::SHA256> pbkdf2; pbkdf2.DeriveKey(key, key.size(), 0, reinterpret_cast<const byte*>(password.data()), password.size(), salt, saltSize, 1513794); return key;}
void EncryptFileIni(const std::string& inputFile, const std::string& outputFile) { CryptoPP::AutoSeededRandomPool prng;
CryptoPP::SecByteBlock salt(16); prng.GenerateBlock(salt, salt.size()); std::string Skey = SecureString("8c6e58842d372667724b0d103f263be82ba360d00dde885c6027f981a62ca8cda0a92864e317f6c51698cc96ae382e2b5596225bb5b521f6c8f7c595f28581542f34823a6a6fd35db7ed53b87e5204575c81599b7bcabd304ce237c558667143ae21158613ec6eeb968555fa3c11c450dbe894f7e0d12f8f3ba89026ed3793f87861179bf9528154983e3619c06822ed5265e9dd2d2b57efd62b95445ebe1461517da99ba5037ecce2a3768a13e09295bb1d6d8ea3e37008b5b6f5e0e742da86a0d8b142bfbb9fc93ed8ed3c592235299d1c0786e48a8f74529f838d1771a09024f6e4b77625689936eae259e67ec0e4238d4297ac1aea37e0ce957f73ea33ee243feb21929a34751718b4bf4343742dcd23d8cdbe447df2461243691cc65890517d5cc207e6f34c6d2b5f94fafc71236de3e9ed4d520df33ce735821192ffa00d1169a5f64bea66c60e56c748adc4c68b8c956668c8ba0d4f31ad4dd0da3fc384987f369d3d5bf46b498bf0fe80e9c95bc5ac723f225e"); CryptoPP::SecByteBlock key = DeriveKeyFromPassword(Skey, salt, salt.size()); CryptoPP::SecByteBlock iv(12); prng.GenerateBlock(iv, iv.size()); CryptoPP::GCM<CryptoPP::AES>::Encryption aesEncryption; aesEncryption.SetKeyWithIV(key.data(), key.size(), iv, iv.size()); std::ifstream inFile(inputFile, std::ios::binary); std::ofstream outFile(outputFile, std::ios::binary); if (!inFile || !outFile) { throw std::runtime_error(SecureString("Erro ao abrir arquivos.")); } outFile.write(reinterpret_cast<const char*>(salt.data()), salt.size()); outFile.write(reinterpret_cast<const char*>(iv.data()), iv.size()); CryptoPP::AuthenticatedEncryptionFilter encryptor( aesEncryption, new CryptoPP::FileSink(outFile), false, CryptoPP::AES::BLOCKSIZE ); CryptoPP::FileSource fs(inFile, true, new CryptoPP::Redirector(encryptor)); key.CleanNew(key.size()); salt.CleanNew(salt.size()); iv.CleanNew(iv.size()); std::fill(Skey.begin(), Skey.end(), 0); - Assistant