解密.ini,并使用值
Decrypt .ini, and use values?
>我有一个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;
}
我的错误在哪里?一些帮助将不胜感激,非常感谢!
你能做的是:
-
逐行读取文件,并将键和值分开,即您看到"键=值"将其分解为键和值。
-
加密值。
-
对值进行 Base64 编码,以防它在文件编码中不再是有效的文本。
-
将该行替换为"key=base64-encoded-value"。
-
稍后,当您读取密钥的编码值(只是一个简单的 Base64 编码的字节字符串)时,Base64 对字符串进行解码,然后解密该值。
例如,此行:
包鲍 = 1
将值"1"作为字符串,并使用函数对其进行加密。在这种情况下,结果是一个可打印的字符串"w"。但是,我会将其视为任意字节。
对"加密"值进行 Base64 编码。例如,UTF-8(或 ASCII)中"w"的 Base64 编码是"dw=="。
将该行替换为:
包鲍 = 载重吨==
或者,如果您愿意:
包鲍 = "DW=="
稍后,当您读取 baubau 的值时,您只需对 Base64 解码 'dw==',获取 'w',然后解密 'w' 到达 '1'。
相关文章:
- AES加密到解密未正确输出
- 为什么这不是解密
- 通过 Openssl 命令行加密,通过 c++ 解密
- OpenSSL 解密功能无法正常工作
- 仿射密码解密,输出大小写不同
- 将加密消息从 php 发送到 C++ 应用程序,然后使用 CryptoPP 进行解密
- 私钥解密代码使用公共接口说明符到 BSAFE 库 v6.0?
- POCO C++加密/解密
- 从加密项目向量中解密任意选择的元素会导致无效的 PKCS #7 块错误
- Ini 文件类型名称 预期C++
- 尝试从 Visual Studios C++ 中的加密字符串输出解密字符串时出现逻辑错误
- OpenSSL RSA 解密随机失败 C/C++
- 压缩天然气.AES.错误解密(可能加密)的文件
- C++ - 从文件解密字符串
- C++ - 如何从上到下制作 4x4 矩阵和 cout 列(需要解密字符串)
- 运行密钥密码解密知道密钥?
- 如何在c ++中使用XOR解密文件?
- 如何制作一个程序,它使用特定单词加密和解密消息?
- 基本加密和解密方法不起作用 C++ 11.
- 解密.ini,并使用值