
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Encrypting web.config Information
|
1005
CertificateValidationCallback method is called whenever a server certificate needs
to be validated. The server certificate is checked and any errors are passed into this
delegate method to allow you to handle them as you wish.
The
AuthenticateAsClient method is called next to authenticate the server:
sslStream.AuthenticateAsClient("MyTestCert2");
As you can see, with a little extra work, you can replace the current stream type you
are using with the
SslStream to gain the benefits of the SSL protocol.
See Also
See the “SslStream Class” topic in the MSDN documentation.
17.17 Encrypting web.config Information
Problem
You need to encrypt data within a web.config file programmatically.
Solution
To encrypt data within a web.config file section, use the following method:
public static void EncryptWebConfigData(string appPath,
string protectedSection,
string dataProtectionProvider)
{
System.Configuration.Configuration webConfig =
WebConfigurationManager.OpenWebConfiguration(appPath);
ConfigurationSection webConfigSection = webConfig.GetSection(protectedSection);
if (!webConfigSection.SectionInformation.IsProtected)
{
webConfigSection.SectionInformation.ProtectSection(dataProtectionProvider);
webConfig.Save( );
}
}
To decrypt data within a web.config file section, ...