DpapiProtectedConfigurationProvider クラス
アセンブリ: System.Configuration (system.configuration.dll 内)

Public NotInheritable Class DpapiProtectedConfigurationProvider Inherits ProtectedConfigurationProvider

DpapiProtectedConfigurationProvider を使用すると、構成ファイルに格納されている機密情報を未承認のアクセスから保護できます。
このクラスのインスタンスを作成するのではなく、構成ファイル内でプロバイダと適切な設定を宣言することによって、標準の DpapiProtectedConfigurationProvider を使用します。次の例を参照してください。
保護された構成の詳細については、「保護された構成を使用した構成情報の暗号化」を参照してください。
DpapiProtectedConfigurationProvider は、Windows ビルトイン暗号化サービスを使用し、コンピュータ固有の保護またはユーザー アカウント固有の保護に合わせて構成できます。コンピュータ固有の保護は、匿名サービスの場合に便利ですが、セキュリティのレベルは低くなります。ユーザー アカウント固有の保護は、特定のユーザー ID で実行されているサービスに使用できます。

標準の 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.Configuration.Provider.ProviderBase
System.Configuration.ProtectedConfigurationProvider
System.Configuration.DpapiProtectedConfigurationProvider


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DpapiProtectedConfigurationProvider コンストラクタ
アセンブリ: System.Configuration (system.configuration.dll 内)



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DpapiProtectedConfigurationProvider クラス
DpapiProtectedConfigurationProvider メンバ
System.Configuration 名前空間
DpapiProtectedConfigurationProvider プロパティ

名前 | 説明 | |
---|---|---|
![]() | Description | 管理ツールまたは他のユーザー インターフェイス (UI) での表示に適した、簡単でわかりやすい説明を取得します。 ( ProviderBase から継承されます。) |
![]() | Name | 構成時にプロバイダを参照するために使用される表示名を取得します。 ( ProviderBase から継承されます。) |
![]() | UseMachineProtection | DpapiProtectedConfigurationProvider オブジェクトがコンピュータ固有の保護またはユーザー アカウント固有の保護のいずれを使用しているかを示す値を取得します。 |

DpapiProtectedConfigurationProvider メソッド

名前 | 説明 | |
---|---|---|
![]() | Decrypt | オーバーライドされます。 渡される XmlNode オブジェクトを復号化します。 |
![]() | Encrypt | オーバーライドされます。 渡される XmlNode オブジェクトを暗号化します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | Initialize | オーバーライドされます。 既定の設定でプロバイダを初期化します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

DpapiProtectedConfigurationProvider メンバ
Windows データ保護 API (DPAPI: Data Protection API) を使用して構成データの暗号化と復号化を行う ProtectedConfigurationProvider オブジェクトを提供します。
DpapiProtectedConfigurationProvider データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | DpapiProtectedConfigurationProvider | 既定の設定を使用して DpapiProtectedConfigurationProvider クラスの新しいインスタンスを初期化します。 |

名前 | 説明 | |
---|---|---|
![]() | Description | 管理ツールまたは他のユーザー インターフェイス (UI) での表示に適した、簡単でわかりやすい説明を取得します。(ProviderBase から継承されます。) |
![]() | Name | 構成時にプロバイダを参照するために使用される表示名を取得します。(ProviderBase から継承されます。) |
![]() | UseMachineProtection | DpapiProtectedConfigurationProvider オブジェクトがコンピュータ固有の保護またはユーザー アカウント固有の保護のいずれを使用しているかを示す値を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Decrypt | オーバーライドされます。 渡される XmlNode オブジェクトを復号化します。 |
![]() | Encrypt | オーバーライドされます。 渡される XmlNode オブジェクトを暗号化します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | Initialize | オーバーライドされます。 既定の設定でプロバイダを初期化します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- DpapiProtectedConfigurationProviderのページへのリンク