私の設定ファイルには、より高度な暗号化が必要な機密情報があります。RsaProtectedConfigurationProviderを使用して設定ファイルのセクションを暗号化/復号化する方法
これは私のコード(作業として期待される)である:暗号化の.configはこのようになります
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="username" value="a2zmenu"/>
<add key="password" value="password"/>
</appSettings>
</configuration>
:
class Program
{
static void Main(string[] args)
{
System.Configuration.ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"D:\Web_S\Prep\test\test.exe.config";
System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
string userNameWithoutEncryption = configuration.AppSettings.Settings["username"].Value;
EncryptAppSettings("appSettings", configuration);
}
protected static void EncryptAppSettings(string section, Configuration configuration)
{
AppSettingsSection objAppsettings = (AppSettingsSection)configuration.GetSection(section);
objAppsettings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
objAppsettings.SectionInformation.ForceSave = true;
configuration.Save(ConfigurationSaveMode.Modified);
}
}
の.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="customAppSettings" type="System.Configuration.NameValueSectionHandler" />
</configSections>
<appSettings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>09+Lm23xDWWnAZFOagh3NRwp5tzad+3oedvTgoeWqunQBiAfk9UGfGxriZg6snwwANUDzOANZ+wOFUb6qa0Atf
NgSd6b4FFSKTqzkfLlk+S9GtPSAVrRaLU9
/Q2Qu7oxoSbhW7NWtengJbEZrFm+GqlLlm08w8Np/y03DMExFeA=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>qSYRXNEKhbwNodH60c7qoWeKZ2QKVQmizPXVGCgHVZPMQ4F+XDqlZa2OyIin0kEI3j8pCjNL097RlZClgdd
gPEd61AEw6DXJc43Z98obNFHmXfK9aS67qEtO6E
T+qCWQq2ZRbfK6xZ6jlfeink35/veUmoxAmDXrkwdrbQVKv98=</CipherValue>
</CipherData>
</EncryptedData>
</appSettings>
</configuration>
私が持っています次の質問: 情報を提供することは安全ですか?たとえば、
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
などの.config?
これらの情報で復号化できないのですか?ファイルは、この行を使用して暗号化された後、私は、ユーザー名の値を取得しようとすると
EncryptAppSettings("appSettings", configuration);
:ファイルが暗号化されて したら、私は、この行をコメントできることを確認することができます
string userNameafterEncryption = configuration.AppSettings.Settings["username"].Value;
私が取得私のファイルが今暗号化されていても復号化された値。私は
は、あなたが設定の暗号化は本当にあなたを保護する方法を、何から理解する必要があなたの助け
このような説明を書く時間をいただき、ありがとうございます。私はあなたの答えを受け入れるだろう(少し待たなければならない) – FieryA