DpapiProtectedConfigurationProviderとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DpapiProtectedConfigurationProviderの意味・解説 

DpapiProtectedConfigurationProvider クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

Windows データ保護 API (DPAPI: Data Protection API) を使用して構成データ暗号化と復号化を行う ProtectedConfigurationProvider オブジェクト提供します

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

Public NotInheritable Class
 DpapiProtectedConfigurationProvider
    Inherits ProtectedConfigurationProvider
Dim instance As DpapiProtectedConfigurationProvider
public sealed class DpapiProtectedConfigurationProvider
 : ProtectedConfigurationProvider
public ref class DpapiProtectedConfigurationProvider
 sealed : public ProtectedConfigurationProvider
public final class DpapiProtectedConfigurationProvider
 extends ProtectedConfigurationProvider
public final class DpapiProtectedConfigurationProvider
 extends ProtectedConfigurationProvider
解説解説
使用例使用例

標準DpapiProtectedConfigurationProvider使用して構成セクション保護保護解除を行う方法次の例に示します

Imports System
Imports System.Configuration


Public Class UsingDpapiProtectedConfigurationProvider


    ' Protect the connectionStrings section.
    Private Shared Sub ProtectConfiguration()

        ' Get the application configuration file.
        Dim config As System.Configuration.Configuration
 = _
        ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

        ' Define the Dpapi provider name.
        Dim provider As String
 = _
            "DataProtectionConfigurationProvider"


        ' Get the section to protect.
        Dim connStrings As ConfigurationSection
 = _
        config.ConnectionStrings

        If Not (connStrings Is
 Nothing) Then
            If Not connStrings.SectionInformation.IsProtected
 Then
                If Not connStrings.ElementInformation.IsLocked
 Then
                    ' Protect the section.

                    connStrings.SectionInformation.ProtectSection(provider)


                    connStrings.SectionInformation.ForceSave = True

                    config.Save(ConfigurationSaveMode.Full)

                    Console.WriteLine( _
                    "Section {0} is now protected by {1}",
 _
                    connStrings.SectionInformation.Name, _
                    connStrings.SectionInformation.ProtectionProvider.Name)

                Else
                    Console.WriteLine( _
                    "Can't protect, section {0} is locked",
 _
                    connStrings.SectionInformation.Name)
                End If
            Else
                Console.WriteLine( _
                "Section {0} is already protected by {1}",
 _
                connStrings.SectionInformation.Name, _
                connStrings.SectionInformation.ProtectionProvider.Name)
            End If

        Else
            Console.WriteLine( _
            "Can't get the section {0}", _
            connStrings.SectionInformation.Name)
        End If
    End Sub 'ProtectConfiguration



    ' Unprotect the connectionStrings section.
    Private Shared Sub UnProtectConfiguration()

        ' Get the application configuration file.
        Dim config As System.Configuration.Configuration
 = _
        ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

        ' Get the section to unprotect.
        Dim connStrings As ConfigurationSection
 = _
        config.ConnectionStrings

        If Not (connStrings Is
 Nothing) Then
            If connStrings.SectionInformation.IsProtected Then
                If Not connStrings.ElementInformation.IsLocked
 Then
                    ' Unprotect the section.
                    connStrings.SectionInformation.UnprotectSection()

                    connStrings.SectionInformation.ForceSave = True
                    config.Save(ConfigurationSaveMode.Full)

                    Console.WriteLine( _
                    "Section {0} is now unprotected.",
 _
                    connStrings.SectionInformation.Name)

                Else
                    Console.WriteLine( _
                    "Can't unprotect, section {0} is locked",
 _
                    connStrings.SectionInformation.Name)
                End If
            Else
                Console.WriteLine( _
                "Section {0} is already unprotected.",
 _
                connStrings.SectionInformation.Name)
            End If

        Else
            Console.WriteLine( _
            "Can't get the section {0}", _
            connStrings.SectionInformation.Name)
        End If
    End Sub 'UnProtectConfiguration



    Public Shared Sub Main(ByVal
 args() As String)

        Dim selection As String
 = String.Empty

        If args.Length = 0 Then
            Console.WriteLine( _
            "Select protect or unprotect")
            Return
        End If

        selection = args(0).ToLower()

        Select Case selection
            Case "protect"
                ProtectConfiguration()

            Case "unprotect"
                UnProtectConfiguration()

            Case Else
                Console.WriteLine( _
                "Unknown selection")
        End Select

        Console.Read()
    End Sub 'Main

End Class 'UsingDpapiProtectedConfigurationProvider

using System;
using System.Configuration;

public class UsingDpapiProtectedConfigurationProvider
{

    // Protect the connectionStrings section.
    private static void
 ProtectConfiguration()
    {

        // Get the application configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

        // Define the Dpapi provider name.
        string provider = 
            "DataProtectionConfigurationProvider";


        // Get the section to protect.
        ConfigurationSection connStrings =
            config.ConnectionStrings;

        if (connStrings != null)
        {
            if (!connStrings.SectionInformation.IsProtected)
            {
                if (!connStrings.ElementInformation.IsLocked)
                {
                    // Protect the section.
                    connStrings.SectionInformation.ProtectSection(provider);

                    connStrings.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);

                    Console.WriteLine("Section {0} is now protected
 by {1}",
                        connStrings.SectionInformation.Name,
                        connStrings.SectionInformation.ProtectionProvider.Name);

                }
                else
                    Console.WriteLine(
                         "Can't protect, section {0} is locked",
                         connStrings.SectionInformation.Name);
            }
            else
                Console.WriteLine(
                    "Section {0} is already protected by
 {1}",
                    connStrings.SectionInformation.Name,
                    connStrings.SectionInformation.ProtectionProvider.Name);

        }
        else
            Console.WriteLine("Can't get the section {0}"
,
                connStrings.SectionInformation.Name);

    }


    // Unprotect the connectionStrings section.
    private static void
 UnProtectConfiguration()
    {

        // Get the application configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

        // Get the section to unprotect.
        ConfigurationSection connStrings =
            config.ConnectionStrings;

        if (connStrings != null)
        {
            if (connStrings.SectionInformation.IsProtected)
            {
                if (!connStrings.ElementInformation.IsLocked)
                {
                    // Unprotect the section.
                    connStrings.SectionInformation.UnprotectSection();

                    connStrings.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);

                    Console.WriteLine("Section {0} is now unprotected."
,
                        connStrings.SectionInformation.Name);

                }
                else
                    Console.WriteLine(
                         "Can't unprotect, section {0} is locked",
                         connStrings.SectionInformation.Name);
            }
            else
                Console.WriteLine(
                    "Section {0} is already unprotected.",
                    connStrings.SectionInformation.Name);

        }
        else
            Console.WriteLine("Can't get the section {0}"
,
                connStrings.SectionInformation.Name);

    }


    public static void Main(string[]
 args)
    {

        string selection = string.Empty;

        if (args.Length == 0)
        {
            Console.WriteLine(
                "Select protect or unprotect");
            return;
        }

        selection = args[0].ToLower();

        switch (selection)
        {
            case "protect":
                ProtectConfiguration();
                break;

            case "unprotect":
                UnProtectConfiguration();
                break;

            default:
                Console.WriteLine("Unknown selection");
                break;
        }

        Console.Read();

    }


}

次の構成抜粋は、保護適用前および適用後の構成セクション示したものです。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="NorthwindConnectionString" 
      connectionString="Data Source=webnetue2;Initial Catalog=Northwind;User ID=aspnet_test;Password=test"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <EncryptedData>
      <CipherData>                <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAcAMh0jIC1kigyFfd9AUZfQQAAAACAAAAAAADZgAAqAAAABAAAADQwbQ2DgIgIlqskE1RI9UpAAAAAASAAACgAAAAEAAAAAXlYBxi3jhM6wv4sxLhugsQAgAAgoReHZS2406dc/AyRDd6WuNr4ihHn6fbipd4tzHEmeuyS4o4fS4CmT3jMt/WjsP/kR7TF4ygwr2GG47podK79ECpVCZHAgctCauCYjE2Ls3iphKXy/pHic2o6aaClt/xPm+fb4OfODv6XjrJhJzGK2lqUPXkyJN1w2zwh6OVpDQF9N8vTyxL4eitp35/M5zYbW7e6VVAgYUOxlNxgCV5+jXpUKh/rPovopTD392u8KavqQFW1iu+gBPSPq/xeZNz+qYMKbUl+r4VTzBQg3fPlRxp1lNZmM2yRgUbkYPNaFb9ihS7GAg5/wZn8lLmThvq39eA0Vlp6hDE92iop885umELt0/NBKf5umQCqqz9EXXLbmmGc7qoLqTaYVuOmqx0LsvrJL0wSL1dSySCjmB/dNAtVUYgg02eWQNKyaLqnpMdCbTLLQ/oCKuNkL5OQ7t1yl5wQGjQhieIRzLtrMgpTSyaHbqDsRurp9Bc5mM078IAg1hXquQNKlJC/wiJ9kbHerFCbtuLGy/7nXVrFH91ud4U4ExCJEuhoTdmuql5kbqYd6Ye/bu2CftPni19nDkSJ8w4NoqMNKbK3Mi/Cd0o113HsVYlETMv1vlJWZWYP91PK9trixiY4E0G81c6IKITjHDrOJ9evdw2T1/TrvY6pzre3UXSJbFMDQVX6JoAxFk02SRZDKOZdRojeoX19lgrFAAAABzjlz3Qg2as3vn7MRQVxDfZucgE</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>
  <configProtectedData defaultProvider="RsaProtectedConfigurationProvider">
    <providers>
      <clear />
      <add keyContainerName="NetFrameworkConfigurationKey" cspProviderName=""
        useMachineContainer="true" useOAEP="false" description="Uses RsaCryptoServiceProvider
 to encrypt and decrypt"
        name="RsaProtectedConfigurationProvider" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration,
 Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add useMachineProtection="true" description="Uses CryptProtectData and
 CryptUnProtectData Windows APIs to encrypt and decrypt"
        keyEntropy="" name="DataProtectionConfigurationProvider" type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration,
 Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </providers>
  </configProtectedData>
</configuration>
継承階層継承階層
System.Object
   System.Configuration.Provider.ProviderBase
     System.Configuration.ProtectedConfigurationProvider
      System.Configuration.DpapiProtectedConfigurationProvider
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DpapiProtectedConfigurationProvider コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

既定設定使用して DpapiProtectedConfigurationProvider クラス新しインスタンス初期化します。

名前空間: System.Configuration
アセンブリ: System.Configuration (system.configuration.dll 内)
構文構文

Dim instance As New DpapiProtectedConfigurationProvider
public DpapiProtectedConfigurationProvider ()
public:
DpapiProtectedConfigurationProvider ()
public DpapiProtectedConfigurationProvider ()
public function DpapiProtectedConfigurationProvider
 ()
解説解説

DpapiProtectedConfigurationProvider コンストラクタは、コード直接使用するためのものではありません。ASP.NET 構成システムによって呼び出されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DpapiProtectedConfigurationProvider クラス
DpapiProtectedConfigurationProvider メンバ
System.Configuration 名前空間

DpapiProtectedConfigurationProvider プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

DpapiProtectedConfigurationProvider クラス
System.Configuration 名前空間
RSAProtectedConfigurationProvider

その他の技術情報

暗号サービス
保護され構成プロバイダ指定

DpapiProtectedConfigurationProvider メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DpapiProtectedConfigurationProvider クラス
System.Configuration 名前空間
RSAProtectedConfigurationProvider

その他の技術情報

暗号サービス
保護され構成プロバイダ指定

DpapiProtectedConfigurationProvider メンバ

Windows データ保護 API (DPAPI: Data Protection API) を使用して構成データ暗号化と復号化を行う ProtectedConfigurationProvider オブジェクト提供します

DpapiProtectedConfigurationProvider データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DpapiProtectedConfigurationProvider 既定設定使用して DpapiProtectedConfigurationProvider クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DpapiProtectedConfigurationProvider クラス
System.Configuration 名前空間
RSAProtectedConfigurationProvider

その他の技術情報

暗号サービス
保護され構成プロバイダ指定



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DpapiProtectedConfigurationProvider」の関連用語

DpapiProtectedConfigurationProviderのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DpapiProtectedConfigurationProviderのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS