我正在尝试加密整个INI文件,使其无法读取。我的代码重复了同一行。下面的代码运行3次,结果插入到INI文件中:
[c7DuuqP28h8 =]
nJvr1BlIML2vaJtyHa4jHw === X84CG / IurDg =
nJvr1BlIML2vaJtyHa4jHw === X84CG / IurDg =
nJvr1BlIML2vaJtyHa4jHw === X84CG / IurDg =
这是我的代码:
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,
string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
public void IniWriteValue(string Section, string Key, string Value)
{
if (!String.IsNullOrEmpty(passphrase))
{
Section = Encryption.EncryptString(Section, passphrase);
Key = Encryption.EncryptString(Key, passphrase);
Value = Encryption.EncryptString(Value, passphrase);
}
WritePrivateProfileString(Section, Key, Value, this.path);
}
//Calling the function
ini.IniWriteValue("Login", "username", chkRememberUsername.Checked ? username.Text : "");
更新
如果Keyname或Value包含=符号,则该行变为与原始行不同的行。所以我需要从Keyname和amp;中删除= sign。值。我google了&发现Pack&解压缩Marc Gravell的解决方案并反向使用它来编码=符号。