SectionInformation.ProtectSection(String) 메서드

정의

보호를 위해 구성 섹션에 표시합니다.

public:
 void ProtectSection(System::String ^ protectionProvider);
public void ProtectSection (string protectionProvider);
member this.ProtectSection : string -> unit
Public Sub ProtectSection (protectionProvider As String)

매개 변수

protectionProvider
String

사용할 보호 공급자의 이름입니다.

예외

AllowLocation 속성은 false로 설정됩니다.

또는

대상 섹션이 이미 보호된 데이터 섹션인 경우

예제

다음 예제에서는 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 보호 공급자로 사용됩니다.

보호된 구성 섹션에 대한 자세한 내용은 보호된 구성을 사용하여 구성 정보 암호화를 참조하세요.

적용 대상

추가 정보