SectionInformation.ProtectSection(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
構成セクションを保護対象としてマークします。
public:
void ProtectSection(System::String ^ protectionProvider);
public void ProtectSection(string protectionProvider);
member this.ProtectSection : string -> unit
Public Sub ProtectSection (protectionProvider As String)
パラメーター
- protectionProvider
- String
使用する保護プロバイダーの名前。
例外
例
次の例は、 ProtectSection メソッドの使用方法を示しています。
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);
}
Public Shared Sub ProtectSection()
' Get the current configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Get the section.
Dim section As UrlsSection = _
CType(config.GetSection("MyUrls"), UrlsSection)
' 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.
Dim sectionXml As String = _
section.SectionInformation.GetRawXml()
Console.WriteLine("Decrypted section:")
Console.WriteLine(sectionXml)
End Sub
注釈
ProtectSectionメソッドは、セクションを暗号化用にマークして、ディスク上に暗号化された形式で書き込みます。
既定では、次の保護プロバイダーが含まれています。
DpapiProtectedConfigurationProvider
RsaProtectedConfigurationProvider
注
null パラメーターまたは空の文字列を使用して ProtectSection メソッドを呼び出すと、RsaProtectedConfigurationProvider クラスが保護プロバイダーとして使用されます。