DpapiProtectedConfigurationProvider 类

定义

提供一个使用 Windows 数据保护 API (DPAPI) 来加密和解密配置数据的 ProtectedConfigurationProviderProvides a ProtectedConfigurationProvider object that uses the Windows data protection API (DPAPI) to encrypt and decrypt configuration data.

public ref class DpapiProtectedConfigurationProvider sealed : System::Configuration::ProtectedConfigurationProvider
public sealed class DpapiProtectedConfigurationProvider : System.Configuration.ProtectedConfigurationProvider
type DpapiProtectedConfigurationProvider = class
    inherit ProtectedConfigurationProvider
Public NotInheritable Class DpapiProtectedConfigurationProvider
Inherits ProtectedConfigurationProvider
继承
DpapiProtectedConfigurationProvider

示例

下面的示例演示如何使用标准DpapiProtectedConfigurationProvider来保护或取消保护配置节。The following example shows how to use the standard DpapiProtectedConfigurationProvider to protect or unprotect a configuration section.

以下配置摘录显示了应用保护之前和之后的配置节。The following configuration excerpts show the configuration section before and after the protection has been applied.

<?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>  

注解

DpapiProtectedConfigurationProvider允许您保护存储在配置文件中的敏感信息不受未经授权的访问。The DpapiProtectedConfigurationProvider allows you to protect sensitive information stored in a configuration file from unauthorized access.

通过在配置文件DpapiProtectedConfigurationProvider中声明提供程序和适当的设置, 而不是创建此类的实例, 可以使用该标准。You use the standard DpapiProtectedConfigurationProvider by declaring the provider and appropriate settings in the configuration file rather than creating an instance of this class. 请参阅下一个示例。Refer to the next example.

有关受保护配置的详细信息, 请参阅使用受保护的配置加密配置信息For more information about Protected Configuration, see Encrypting Configuration Information Using Protected Configuration.

DpapiProtectedConfigurationProvider使用 Windows 内置的加密服务, 可以为特定于计算机或特定于用户帐户的保护进行配置。The DpapiProtectedConfigurationProvider uses the Windows built-in cryptographic services and can be configured for either machine-specific or user-account-specific protection. 计算机特定的保护对匿名服务非常有用, 但安全性较低。Machine-specific protection is useful for anonymous services but provides less security. 用户帐户特定的保护可用于以特定用户身份运行的服务。User-account-specific protection can be used with services that run with a specific user identity.

构造函数

DpapiProtectedConfigurationProvider()

使用默认设置初始化 DpapiProtectedConfigurationProvider 类的新实例。Initializes a new instance of the DpapiProtectedConfigurationProvider class using default settings.

属性

Description

获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)
Name

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)
UseMachineProtection

获取一个值,该值用于指示 DpapiProtectedConfigurationProvider 对象是在使用特定于计算机的保护,还是在使用特定于用户帐户的保护。Gets a value that indicates whether the DpapiProtectedConfigurationProvider object is using machine-specific or user-account-specific protection.

方法

Decrypt(XmlNode)

对传递的 XmlNode 对象进行解密。Decrypts the passed XmlNode object.

Encrypt(XmlNode)

对传递的 XmlNode 对象进行加密。Encrypts the passed XmlNode object.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Initialize(String, NameValueCollection)

使用默认设置初始化提供程序。Initializes the provider with default settings.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

安全性

NamedPermissionSet
用于完全访问系统资源。for full access to system resources. 需求值:DemandFullTrustDemand value: DemandFullTrust

适用于

另请参阅