Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么INI文件包含重复的行?_C#_Ini - Fatal编程技术网

C# 为什么INI文件包含重复的行?

C# 为什么INI文件包含重复的行?,c#,ini,C#,Ini,我试图加密整个INI文件,使其无法读取。我的代码重复了同一行。以下代码运行3次,结果插入INI文件: [c7DuuqP28h8=] nJvr1BlIML2vaJtyHa4jHw==X84CG/IurDg= nJvr1BlIML2vaJtyHa4jHw==X84CG/IurDg= nJvr1BlIML2vaJtyHa4jHw==X84CG/IurDg= 这是我的密码: [DllImport("kernel32")] private static extern long WriteP

我试图加密整个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);
    }

更新:

这是因为如果Keyname或Value包含=sign,那么该行将与原始行不同。所以我需要从Keyname和Value中删除=符号。我在谷歌上搜索并找到了的打包和解包解决方案,并将其反向用于编码=符号


@Paolo我认为,标题“[INI文件密钥名长度是多少?””暗示了这一点。不过,OP应该说明这一点。好的,明白了键名末尾的符号造成混乱。nJvr1BlIML2vaJtyHa4jHw===X84CG/IurDg=应为“nJvr1BlIML2vaJtyHa4jHw==”=“X84CG/IurDg=”
      //Calling the function
      ini.IniWriteValue("Login", "username", chkRememberUsername.Checked ? username.Text : "");