Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.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
如何将Bin文件夹中的配置文件转换为非人类可读的格式?(c#)_C#_Encryption_Config Files_Bin Folder - Fatal编程技术网

如何将Bin文件夹中的配置文件转换为非人类可读的格式?(c#)

如何将Bin文件夹中的配置文件转换为非人类可读的格式?(c#),c#,encryption,config-files,bin-folder,C#,Encryption,Config Files,Bin Folder,设置项目后,bin文件夹中有一些.config文件。我想让它们成为非人类可读的格式。 1.我知道我可以使用命令,比如asp net\ureg I I s-pe…,但该项目是一个Win-Form项目,在我的配置文件中没有类似Web.config的部分。我的配置文件格式如下: <...> <add key="..." value="...." /> <add key="..." value="..." /> </...> 我还尝试加密配置

设置项目后,bin文件夹中有一些.config文件。我想让它们成为非人类可读的格式。 1.我知道我可以使用命令,比如
asp net\ureg I I s-pe…
,但该项目是一个Win-Form项目,在我的配置文件中没有类似Web.config的部分。我的配置文件格式如下:

<...>
  <add key="..." value="...." />
  <add key="..." value="..." />
</...>

  • 我还尝试加密配置文件,但是有很多地方调用配置文件。这样做似乎太复杂了
    那么,是否有一些简单的方法可以使用C#将bin文件夹中的配置文件转换为非人类可读的格式?

    您有两个选择。。如果您对保护某些特殊参数(例如密码)感兴趣,则只需对其进行加密,并且仅具有加密值。如果您确实想保护整个内容,可以使用SectionInformation.ProtectSection

    MSDN的示例代码:

    static public void ProtectSection()
    {
    
        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);
    
    
        // Get the section.
        UrlsSection section =
            (UrlsSection)config.GetSection("MyUrls");
    
    
        // Protect (encrypt)the section.
        section.SectionInformation.ProtectSection(
            "RsaProtectedConfigurationProvider");
    
        // Save the encrypted section.
        section.SectionInformation.ForceSave = true;
    
        config.Save(ConfigurationSaveMode.Full);
    
        // Display decrypted configuration  
        // section. Note, the system 
        // uses the Rsa provider to decrypt 
        // the section transparently. 
        string sectionXml =
            section.SectionInformation.GetRawXml();
    
        Console.WriteLine("Decrypted section:");
        Console.WriteLine(sectionXml);
    
    }
    

    你的目标是什么,让它们非人类可读?这些文件中有什么特别的东西值得保护吗?我不希望用户更改配置文件中Key或Value的内容。他们总是能够这样做的,只是让它变得更困难并不能阻止真正有决心的人。此外,编辑此类文件的人可能知道它可能会产生不必要的副作用,但在任何情况下,如果配置丢失或无效,您的程序可能会假定一些合理的默认值。