forked from OfficialIncubo/BeatDrop-Music-Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption_utils.cpp
More file actions
45 lines (39 loc) · 1.44 KB
/
encryption_utils.cpp
File metadata and controls
45 lines (39 loc) · 1.44 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
#include <windows.h>
#include <wincrypt.h>
#include <string>
#include <vector>
class EncryptionUtils {
public:
static std::string Encrypt(const std::string& plaintext) {
DATA_BLOB DataIn;
DATA_BLOB DataOut;
DATA_BLOB DataEntropy;
std::string entropy = "SomeEntropy"; // Use a secure entropy value
DataEntropy.pbData = (BYTE*)entropy.data();
DataEntropy.cbData = entropy.size();
DataIn.pbData = (BYTE*)plaintext.data();
DataIn.cbData = plaintext.size();
if (CryptProtectData(&DataIn, NULL, &DataEntropy, NULL, NULL, 0, &DataOut)) {
std::string encrypted((char*)DataOut.pbData, DataOut.cbData);
LocalFree(DataOut.pbData);
return encrypted;
}
return "";
}
static std::string Decrypt(const std::string& encrypted) {
DATA_BLOB DataIn;
DATA_BLOB DataOut;
DATA_BLOB DataEntropy;
std::string entropy = "SomeEntropy"; // Use the same entropy value
DataEntropy.pbData = (BYTE*)entropy.data();
DataEntropy.cbData = entropy.size();
DataIn.pbData = (BYTE*)encrypted.data();
DataIn.cbData = encrypted.size();
if (CryptUnprotectData(&DataIn, NULL, &DataEntropy, NULL, NULL, 0, &DataOut)) {
std::string decrypted((char*)DataOut.pbData, DataOut.cbData);
LocalFree(DataOut.pbData);
return decrypted;
}
return "";
}
};