-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptor.h
More file actions
61 lines (48 loc) · 2.59 KB
/
Encryptor.h
File metadata and controls
61 lines (48 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef ENCRYPTOR_H
#define ENCRYPTOR_H
#include <string>
#include <vector>
#include <functional>
namespace EncryptionLib {
// Transform function: داده را inplace با کلید تغییر میدهد (XOR/AES/...)
using TransformFunction = std::function<void(std::vector<char>&, const std::string&)>;
struct TransformAlgorithm {
TransformFunction encrypt;
TransformFunction decrypt;
};
struct OperationResult {
bool success;
std::string message;
size_t remainingKeys;
};
class Encryptor {
public:
static OperationResult encrypt(const std::string& encryptedFilePath,
const std::string& keysFilePath,
const std::string& zipPassword,
const std::string& inputPath,
const std::vector<TransformAlgorithm>& transformAlgos);
static OperationResult decrypt(const std::string& outputPath,
const std::string& keysFilePath,
const std::string& zipPassword,
const std::string& encryptedFilePath,
const std::vector<TransformAlgorithm>& transformAlgos);
// پیشفرضها
static void defaultXorTransform(std::vector<char>& data, const std::string& key);
static void defaultAesEncryptTransform(std::vector<char>& data, const std::string& key);
static void defaultAesDecryptTransform(std::vector<char>& data, const std::string& key);
private:
static std::string createZipArchive(const std::string& inputPath, const std::string& zipPassword);
static bool extractZipArchive(const std::string& archivePath, const std::string& zipPassword, const std::string& outputPath);
static std::string getTempFilePath(const std::string &extension = ".tmp");
// --- Key ID & Header helpers ---
static std::string computeKeyIdHex(const std::string& key); // SHA-256 hex
static bool writeFileWithHeader(const std::string& outPath, const std::string& keyIdHex, const std::vector<char>& payload);
static bool readFileWithHeader(const std::string& inPath, std::string& keyIdHexOut, std::vector<char>& payloadOut);
// مدیریت کلیدها
static bool loadKeysFile(const std::string& keysFilePath, std::vector<std::string>& keys);
static size_t removeKeyById(const std::string& keysFilePath, const std::string& keyIdHex);
static void dedupeKeysById(std::vector<std::string>& keys); // حذف تکراریها بر اساس keyId
};
} // namespace EncryptionLib
#endif // ENCRYPTOR_H