設定ファイルで任意の情報を保護できます。ウォークスルーへのこのリンク:保護された構成を使用した構成情報の暗号化方法の説明
更新:リンク切れで申し訳ありませんが、更新して記事のタイトルを追加します。解決策は、RsaProtectedConfigurationProviderを使用することです。WebUtilityヘルパークラスで簡単なメソッドを作成しました。
public static void CheckWebConfigSecured(string webPath, params string[] sections)
{
Configuration confg = WebConfigurationManager.OpenWebConfiguration(webPath);
bool done = false;
foreach (string section in sections)
{
ConfigurationSection confSection = confg.GetSection(section);
if ((confSection != null) && !confSection.SectionInformation.IsProtected)
{
confSection.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
done = true;
}
}
if (done)
{
confg.Save();
}
}
Application_BeginRequestでGlobal.asax.csから呼び出します
WebUtility.CheckWebConfigSecured(
context.Request.ApplicationPath,
"connectionStrings",
"appSettings",
"log4net");
ここで、 connectionStrings、appSettings、およびlog4netは、保護したいweb.configセクションです。
結果として、サーバー上のWeb.configファイルのこれらのセクションは、展開後に最初にサイトにアクセスした後、次の例のようになります。
<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>YbjvJF6IpTaEFb58ag1O ... HJm1uzA=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>mzJ2PoteOG7ZpAs922sounmG ... 02D3ZiM1PCliSw==</CipherValue>
</CipherData>
</EncryptedData>
</appSettings>