解密.ini,并使用值

Decrypt .ini, and use values?

本文关键字:ini 解密      更新时间:2023-10-16

>我有一个XOR函数:

string encryptDecrypt(string toEncrypt) {
char key[64] = { 'F', '2', 'D', 'C', '5', '4', '0', 'D', 'B', 'F', '3', 'E', '1', '2', '9', 'F', '4', 'E', 'A', 'A', 'F', '7', '6', '7', '5', '6', '9', 'E', '3', 'C', 'F', '9', '7', '5', '2', 'B', '4', 'B', '8', '2', '6', 'D', '9', '8', 'F', 'D', '8', '3', '8', '4', '6', '0', '8', '5', 'C', '0', '3', '7', 'D', '3', '5', 'F', '7', '5' };
string output = toEncrypt;
for (int i = 0; i < toEncrypt.size(); i++)
    output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
return output;

}

我加密了我的.ini:

[test]
baubau = 1
haha = 2
sometext = blabla

我如何尝试解密和使用值:

std::string Filename = "abc.ini";
std::ifstream input(Filename, std::ios::binary | ios::in);  // Open the file
std::string line;                                           // Temp variable
std::vector<std::string> lines;                             // Vector for holding all lines in the file
while (std::getline(input, line))                           // Read lines as long as the file is
{
lines.push_back(encryptDecrypt(line));
}
// Here i should call the ini reader? but how?
CIniReader iniReader("abc.ini");
string my = encryptDecrypt(iniReader.ReadString("test", "baubau", ""));
for (auto s : lines)   
{
    cout << my;
    cout << endl;                                        
}

我的错误在哪里?一些帮助将不胜感激,非常感谢!

你能做的是:

  1. 逐行读取文件,并将键和值分开,即您看到"键=值"将其分解为键和值。

  2. 加密值。

  3. 对值进行 Base64 编码,以防它在文件编码中不再是有效的文本。

  4. 将该行替换为"key=base64-encoded-value"。

  5. 稍后,当您读取密钥的编码值(只是一个简单的 Base64 编码的字节字符串)时,Base64 对字符串进行解码,然后解密该值。

例如,此行:

包鲍 = 1

将值"1"作为字符串,并使用函数对其进行加密。在这种情况下,结果是一个可打印的字符串"w"。但是,我会将其视为任意字节。

对"加密"值进行 Base64 编码。例如,UTF-8(或 ASCII)中"w"的 Base64 编码是"dw=="。

将该行替换为:

包鲍 = 载重吨==

或者,如果您愿意:

包鲍 = "DW=="

稍后,当您读取 baubau 的值时,您只需对 Base64 解码 'dw==',获取 'w',然后解密 'w' 到达 '1'。