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

Public NotInheritable Class RsaProtectedConfigurationProvider Inherits ProtectedConfigurationProvider

RSAProtectedConfigurationProvider クラスは、構成ファイルに格納されている機密情報を暗号化する方法を提供します。これは、承認されていないアクセスから機密情報を保護するのに役立ちます。このトピックで後述する例で示すように、このクラスのインスタンスを作成するのではなく、構成ファイル内でプロバイダを宣言して適切な設定を行うことによって、組み込みの RSAProtectedConfigurationProvider を使用します。
RSAProtectedConfigurationProvider は、RSA クラスが提供する暗号化機能を使用して、構成セクションの暗号化と復号化を行います。
![]() |
---|
ASP.NET で構成ファイルの暗号化された情報を復号化するには、ASP.NET アプリケーションの ID で、構成データの暗号化および復号化に使用する暗号キーへの読み取りアクセスができる必要があります。詳細については、「チュートリアル : 保護された構成を使用した構成情報の暗号化」を参照してください。 |

標準の RSAProtectedConfigurationProvider を使用して、構成セクションの保護と保護解除を行う方法を次のコード例に示します。
Imports System Imports System.Configuration Public Class UsingRsaProtectedConfigurationProvider ' 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 Rsa provider name. Dim provider As String = _ "RsaProtectedConfigurationProvider" ' 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 'UsingRsaProtectedConfigurationProvider
using System; using System.Configuration; public class UsingRsaProtectedConfigurationProvider { // Protect the connectionStrings section. private static void ProtectConfiguration() { // Get the application configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); // Define the Rsa provider name. string provider = "RsaProtectedConfigurationProvider"; // 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 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>B702tRDVHJjC3CYXt7I0ucCDjdht/Vyk/DdUhwQyt7vepSD85dwCP8ox9Y1BUdjajFeTFfFBsGypbli5HPGRYamQdrVkPo07bBBXNT5H02qxREguGUU4iDtV1Xp8BLVZjQMV4ZgP6Wbctw2xRvPC7GvKHLI4fUN/Je5LmutsijA=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>ME+XJA2TAj3QN3yT4pJq3sRArC0i7Cz3Da71BkaRe9QNfuVuUjcv0jeGUN4wDdOAZ7LPq6UpVrpirY3kQcALDvPJ5nKxk++Mw75rjtIO8eh2goTY9rCK6zanfzaDshFy7IqItpvs/y2kmij25nM3ury6uO0hCf0UbEL1mbT2jXDqvcrHZUobO1Ef6bygBZ/8HpU+VfF9CTCob/BBE9zUkK37EQhcduwsnzBvDblYbF/Rd+F4lxAkZnecGLfCZjOzJB4xH1a0vvWtPR7zNwL/7I0uHzQjyMdWrkBnotMjoR70R7NELBotCogWO0MBimncKigdR3dTTdrCd72a7UJ4LMlEQaZXGIJp4PIg6qVDHII=</CipherValue> </CipherData> </EncryptedData> </connectionStrings> </configuration>

System.Configuration.Provider.ProviderBase
System.Configuration.ProtectedConfigurationProvider
System.Configuration.RsaProtectedConfigurationProvider


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RsaProtectedConfigurationProvider コンストラクタ
アセンブリ: 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RsaProtectedConfigurationProvider プロパティ

名前 | 説明 | |
---|---|---|
![]() | CspProviderName | Windows Cryptography API (crypto API) 暗号化サービス プロバイダ (CSP: Cryptographic Service Provider) の名前を取得します。 |
![]() | Description | 管理ツールまたは他のユーザー インターフェイス (UI) での表示に適した、簡単でわかりやすい説明を取得します。 ( ProviderBase から継承されます。) |
![]() | KeyContainerName | キー コンテナの名前を取得します。 |
![]() | Name | 構成時にプロバイダを参照するために使用される表示名を取得します。 ( ProviderBase から継承されます。) |
![]() | RsaPublicKey | プロバイダが使用するパブリック キーを取得します。 |
![]() | UseMachineContainer | RSAProtectedConfigurationProvider がコンピュータのキー コンテナを使用しているかどうかを示すブール値を取得します。 |
![]() | UseOAEP | プロバイダが OAEP (Optimal Asymmetric Encryption Padding) キー交換データを使用しているかどうかを示す値を取得します。 |

RsaProtectedConfigurationProvider メソッド

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

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

RsaProtectedConfigurationProvider メンバ
構成データの暗号化と復号化を行うために RSA 暗号方式を使用する ProtectedConfigurationProvider を提供します。
RsaProtectedConfigurationProvider データ型で公開されるメンバを以下の表に示します。

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

名前 | 説明 | |
---|---|---|
![]() | CspProviderName | Windows Cryptography API (crypto API) 暗号化サービス プロバイダ (CSP: Cryptographic Service Provider) の名前を取得します。 |
![]() | Description | 管理ツールまたは他のユーザー インターフェイス (UI) での表示に適した、簡単でわかりやすい説明を取得します。(ProviderBase から継承されます。) |
![]() | KeyContainerName | キー コンテナの名前を取得します。 |
![]() | Name | 構成時にプロバイダを参照するために使用される表示名を取得します。(ProviderBase から継承されます。) |
![]() | RsaPublicKey | プロバイダが使用するパブリック キーを取得します。 |
![]() | UseMachineContainer | RSAProtectedConfigurationProvider がコンピュータのキー コンテナを使用しているかどうかを示すブール値を取得します。 |
![]() | UseOAEP | プロバイダが OAEP (Optimal Asymmetric Encryption Padding) キー交換データを使用しているかどうかを示す値を取得します。 |

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

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

- RsaProtectedConfigurationProviderのページへのリンク