Dieser Artikel wurde manuell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. |
Übersetzung
Original
|
RsaProtectedConfigurationProvider-Klasse
Stellt eine Instanz von ProtectedConfigurationProvider bereit, die die RSA-Verschlüsselung verwendet, um Konfigurationsdaten zu verschlüsseln und zu entschlüsseln.
System.Configuration.Provider.ProviderBase
System.Configuration.ProtectedConfigurationProvider
System.Configuration.RsaProtectedConfigurationProvider
Assembly: System.Configuration (in System.Configuration.dll)
Der RsaProtectedConfigurationProvider-Typ macht die folgenden Member verfügbar.
| Name | Beschreibung | |
|---|---|---|
|
RsaProtectedConfigurationProvider | Initialisiert eine neue Instanz der RsaProtectedConfigurationProvider-Klasse. |
| Name | Beschreibung | |
|---|---|---|
|
CspProviderName | Ruft den Namen des Kryptografiedienstanbieters (CSP) der Kryptografie-API von Windows (Crypto-API) ab. |
|
Description | Ruft eine kurze, benutzerfreundliche Beschreibung ab, die für die Anzeige in Verwaltungstools oder anderen Benutzeroberflächen geeignet ist. (Von ProviderBase geerbt.) |
|
KeyContainerName | Ruft den Namen des Schlüsselcontainers ab. |
|
Name | Ruft den Anzeigennamen ab, der verwendet wird, um während der Konfiguration auf den Anbieter zu verweisen. (Von ProviderBase geerbt.) |
|
RsaPublicKey | Ruft den vom Anbieter verwendeten öffentlichen Schlüssel ab. |
|
UseMachineContainer | Ruft einen Wert ab, der angibt, ob das RsaProtectedConfigurationProvider-Objekt den Computerschlüsselcontainer verwendet. |
|
UseOAEP | Ruft einen Wert ab, der angibt, ob der Anbieter OAEP-Schlüsselaustauschdaten (Optimal Asymmetric Encryption Padding) verwendet. |
| Name | Beschreibung | |
|---|---|---|
|
AddKey | Fügt dem RSA-Schlüsselcontainer einen Schlüssel hinzu. |
|
Decrypt | Entschlüsselt den übergebenen XML-Knoten. (Überschreibt ProtectedConfigurationProvider.Decrypt(XmlNode).) |
|
DeleteKey | Entfernt einen Schlüssel aus dem RSA-Schlüsselcontainer. |
|
Encrypt | Verschlüsselt den übergebenen XML-Knoten. (Überschreibt ProtectedConfigurationProvider.Encrypt(XmlNode).) |
|
Equals(Object) | Bestimmt, ob das angegebene Object und das aktuelle Object gleich sind. (Von Object geerbt.) |
|
ExportKey | Exportiert einen RSA-Schlüssel vom Schlüsselcontainer. |
|
Finalize | Gibt einem Objekt Gelegenheit zu dem Versuch, Ressourcen freizugeben und andere Bereinigungen durchzuführen, bevor es von der automatische Speicherbereinigung freigegeben wird. (Von Object geerbt.) |
|
GetHashCode | Fungiert als Hashfunktion für einen bestimmten Typ. (Von Object geerbt.) |
|
GetType | Ruft den Type der aktuellen Instanz ab. (Von Object geerbt.) |
|
ImportKey | Importiert einen RSA-Schlüssel in den Schlüsselcontainer. |
|
Initialize | Initialisiert den Anbieter mit Standardeinstellungen. (Überschreibt ProviderBase.Initialize(String, NameValueCollection).) |
|
MemberwiseClone | Erstellt eine flache Kopie des aktuellen Object. (Von Object geerbt.) |
|
ToString | Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt. (Von Object geerbt.) |
Die RsaProtectedConfigurationProvider-Klasse ermöglicht es Ihnen, vertrauliche Informationen zu verschlüsseln, die in einer Konfigurationsdatei gespeichert sind, wodurch die Datei vor unberechtigtem Zugriff geschützt wird. Sie verwenden die integrierte Instanz von RsaProtectedConfigurationProvider, indem Sie den Anbieter deklarieren und entsprechende Einstellungen in der Konfigurationsdatei vornehmen, anstatt eine Instanz dieser Klasse zu erstellen, wie im Beispiel an späterer Stelle in diesem Thema gezeigt wird.
Das RsaProtectedConfigurationProvider-Objekt verwendet die von der RSA-Klasse zum Ver- und Entschlüsseln von Konfigurationsabschnitten bereitgestellten Kryptografiefunktionen.
Hinweis
|
|---|
|
Bevor ASP.NET verschlüsselte Informationen in der Konfigurationsdatei entschlüsseln kann, muss die Identität der ASP.NET-Anwendung über Lesezugriff auf den Verschlüsselungsschlüssel verfügen, um die Konfigurationsdaten zu verschlüsseln und zu entschlüsseln. Weitere Informationen finden Sie unter Exemplarische Vorgehensweise: Verschlüsseln von Konfigurationsinformationen mithilfe der geschützten Konfiguration. |
Im folgenden Codebeispiel wird veranschaulicht, wie der Standard-RsaProtectedConfigurationProvider verwendet wird, um einen Konfigurationsabschnitt zu schützen oder den Schutz aufzuheben.
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(); } }
Im folgenden Beispiel wird ein Auszug aus einer Konfigurationsdatei nach der Verschlüsselung veranschaulicht.
<?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>
-
SecurityPermission
für den Vollzugriff auf die durch die Berechtigung geschützte Ressource. Demand.
Windows 7, Windows Vista SP1 oder höher, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core wird nicht unterstützt), Windows Server 2008 R2 (Server Core wird mit SP1 oder höher unterstützt), Windows Server 2003 SP2
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Hinweis