Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Configuration / System / Configuration / ProtectedConfigurationSection.cs / 1 / ProtectedConfigurationSection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration
{
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Globalization;
using System.Security.Permissions;
public sealed class ProtectedConfigurationSection : ConfigurationSection
{
internal ProtectedConfigurationProvider GetProviderFromName(string providerName)
{
ProviderSettings ps = Providers[providerName];
if (ps == null) {
throw new Exception(SR.GetString(SR.ProtectedConfigurationProvider_not_found, providerName));
}
return InstantiateProvider(ps);
}
internal ProtectedConfigurationProviderCollection GetAllProviders()
{
ProtectedConfigurationProviderCollection coll = new ProtectedConfigurationProviderCollection();
foreach(ProviderSettings ps in Providers)
{
coll.Add(InstantiateProvider(ps));
}
return coll;
}
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
private ProtectedConfigurationProvider CreateAndInitializeProviderWithAssert(Type t, ProviderSettings pn) {
ProtectedConfigurationProvider provider = (ProtectedConfigurationProvider)TypeUtil.CreateInstanceWithReflectionPermission(t);
NameValueCollection pars = pn.Parameters;
NameValueCollection cloneParams = new NameValueCollection(pars.Count);
foreach (string key in pars) {
cloneParams[key] = pars[key];
}
provider.Initialize(pn.Name, cloneParams);
return provider;
}
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn)
{
Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true);
if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) {
throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider));
}
// Needs to check APTCA bit. See VSWhidbey 429996.
if (!TypeUtil.IsTypeAllowedInConfig(t)) {
throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName));
}
// Needs to check Assert Fulltrust in order for runtime to work. See VSWhidbey 429996.
return CreateAndInitializeProviderWithAssert(t, pn);
}
internal static string DecryptSection(string encryptedXml, ProtectedConfigurationProvider provider) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(encryptedXml);
XmlNode resultNode = provider.Decrypt(doc.DocumentElement);
return resultNode.OuterXml;
}
private const string EncryptedSectionTemplate = "<{0} {1}=\"{2}\"> {3} {0}>";
internal static string FormatEncryptedSection(string encryptedXml, string sectionName, string providerName) {
return String.Format(CultureInfo.InvariantCulture, EncryptedSectionTemplate,
sectionName, // The section to encrypt
BaseConfigurationRecord.KEYWORD_PROTECTION_PROVIDER, // protectionProvider keyword
providerName, // The provider name
encryptedXml // the encrypted xml
);
}
internal static string EncryptSection(string clearXml, ProtectedConfigurationProvider provider) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(clearXml);
string sectionName = xmlDocument.DocumentElement.Name;
XmlNode encNode = provider.Encrypt(xmlDocument.DocumentElement);
return encNode.OuterXml;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
private static ConfigurationPropertyCollection _properties;
private static readonly ConfigurationProperty _propProviders =
new ConfigurationProperty("providers",
typeof(ProtectedProviderSettings),
new ProtectedProviderSettings(),
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propDefaultProvider =
new ConfigurationProperty("defaultProvider",
typeof(string),
"RsaProtectedConfigurationProvider",
null,
ConfigurationProperty.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
static ProtectedConfigurationSection()
{
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add(_propProviders);
_properties.Add(_propDefaultProvider);
}
public ProtectedConfigurationSection()
{
}
protected internal override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
private ProtectedProviderSettings _Providers
{
get
{
return (ProtectedProviderSettings)base[_propProviders];
}
}
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers
{
get
{
return _Providers.Providers;
}
}
[ConfigurationProperty("defaultProvider", DefaultValue = "RsaProtectedConfigurationProvider")]
public string DefaultProvider
{
get
{
return (string)base[_propDefaultProvider];
}
set
{
base[_propDefaultProvider] = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration
{
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Globalization;
using System.Security.Permissions;
public sealed class ProtectedConfigurationSection : ConfigurationSection
{
internal ProtectedConfigurationProvider GetProviderFromName(string providerName)
{
ProviderSettings ps = Providers[providerName];
if (ps == null) {
throw new Exception(SR.GetString(SR.ProtectedConfigurationProvider_not_found, providerName));
}
return InstantiateProvider(ps);
}
internal ProtectedConfigurationProviderCollection GetAllProviders()
{
ProtectedConfigurationProviderCollection coll = new ProtectedConfigurationProviderCollection();
foreach(ProviderSettings ps in Providers)
{
coll.Add(InstantiateProvider(ps));
}
return coll;
}
[PermissionSet(SecurityAction.Assert, Unrestricted=true)]
private ProtectedConfigurationProvider CreateAndInitializeProviderWithAssert(Type t, ProviderSettings pn) {
ProtectedConfigurationProvider provider = (ProtectedConfigurationProvider)TypeUtil.CreateInstanceWithReflectionPermission(t);
NameValueCollection pars = pn.Parameters;
NameValueCollection cloneParams = new NameValueCollection(pars.Count);
foreach (string key in pars) {
cloneParams[key] = pars[key];
}
provider.Initialize(pn.Name, cloneParams);
return provider;
}
private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn)
{
Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true);
if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t)) {
throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider));
}
// Needs to check APTCA bit. See VSWhidbey 429996.
if (!TypeUtil.IsTypeAllowedInConfig(t)) {
throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName));
}
// Needs to check Assert Fulltrust in order for runtime to work. See VSWhidbey 429996.
return CreateAndInitializeProviderWithAssert(t, pn);
}
internal static string DecryptSection(string encryptedXml, ProtectedConfigurationProvider provider) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(encryptedXml);
XmlNode resultNode = provider.Decrypt(doc.DocumentElement);
return resultNode.OuterXml;
}
private const string EncryptedSectionTemplate = "<{0} {1}=\"{2}\"> {3} {0}>";
internal static string FormatEncryptedSection(string encryptedXml, string sectionName, string providerName) {
return String.Format(CultureInfo.InvariantCulture, EncryptedSectionTemplate,
sectionName, // The section to encrypt
BaseConfigurationRecord.KEYWORD_PROTECTION_PROVIDER, // protectionProvider keyword
providerName, // The provider name
encryptedXml // the encrypted xml
);
}
internal static string EncryptSection(string clearXml, ProtectedConfigurationProvider provider) {
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.LoadXml(clearXml);
string sectionName = xmlDocument.DocumentElement.Name;
XmlNode encNode = provider.Encrypt(xmlDocument.DocumentElement);
return encNode.OuterXml;
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
private static ConfigurationPropertyCollection _properties;
private static readonly ConfigurationProperty _propProviders =
new ConfigurationProperty("providers",
typeof(ProtectedProviderSettings),
new ProtectedProviderSettings(),
ConfigurationPropertyOptions.None);
private static readonly ConfigurationProperty _propDefaultProvider =
new ConfigurationProperty("defaultProvider",
typeof(string),
"RsaProtectedConfigurationProvider",
null,
ConfigurationProperty.NonEmptyStringValidator,
ConfigurationPropertyOptions.None);
static ProtectedConfigurationSection()
{
// Property initialization
_properties = new ConfigurationPropertyCollection();
_properties.Add(_propProviders);
_properties.Add(_propDefaultProvider);
}
public ProtectedConfigurationSection()
{
}
protected internal override ConfigurationPropertyCollection Properties
{
get
{
return _properties;
}
}
private ProtectedProviderSettings _Providers
{
get
{
return (ProtectedProviderSettings)base[_propProviders];
}
}
[ConfigurationProperty("providers")]
public ProviderSettingsCollection Providers
{
get
{
return _Providers.Providers;
}
}
[ConfigurationProperty("defaultProvider", DefaultValue = "RsaProtectedConfigurationProvider")]
public string DefaultProvider
{
get
{
return (string)base[_propDefaultProvider];
}
set
{
base[_propDefaultProvider] = value;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataSourceXmlSubItemAttribute.cs
- WebServicesDescriptionAttribute.cs
- RawAppCommandInputReport.cs
- ViewCellSlot.cs
- MonikerSyntaxException.cs
- StorageAssociationTypeMapping.cs
- GridViewColumnCollectionChangedEventArgs.cs
- WebPartDisplayModeCancelEventArgs.cs
- TdsParserHelperClasses.cs
- SwitchAttribute.cs
- PathNode.cs
- BuiltInPermissionSets.cs
- AutoGeneratedFieldProperties.cs
- StoreItemCollection.cs
- WizardStepBase.cs
- LinkTarget.cs
- ChannelManager.cs
- OperationFormatter.cs
- ManipulationInertiaStartingEventArgs.cs
- DynamicDataRouteHandler.cs
- PageRequestManager.cs
- WebSysDescriptionAttribute.cs
- EdmRelationshipNavigationPropertyAttribute.cs
- PriorityQueue.cs
- FastPropertyAccessor.cs
- AspNetCompatibilityRequirementsAttribute.cs
- SqlInfoMessageEvent.cs
- XNameTypeConverter.cs
- XPathDocumentNavigator.cs
- Point.cs
- DiagnosticStrings.cs
- RelationHandler.cs
- DataListItemCollection.cs
- FontCacheLogic.cs
- ToolStripDesignerAvailabilityAttribute.cs
- _HTTPDateParse.cs
- PhysicalFontFamily.cs
- VirtualPathProvider.cs
- BaseTemplateParser.cs
- WebCategoryAttribute.cs
- Utils.cs
- TdsParserSessionPool.cs
- EntitySqlQueryState.cs
- RelativeSource.cs
- XmlAttributeHolder.cs
- ModifiableIteratorCollection.cs
- ConfigurationPropertyCollection.cs
- DataGridViewSelectedCellCollection.cs
- AttributeProviderAttribute.cs
- RequestUriProcessor.cs
- CompatibleIComparer.cs
- ConnectionPoint.cs
- AnnotationObservableCollection.cs
- HideDisabledControlAdapter.cs
- ExtentKey.cs
- GeometryDrawing.cs
- DataGridViewComboBoxColumnDesigner.cs
- Form.cs
- PropertyPushdownHelper.cs
- Policy.cs
- RuleSetDialog.cs
- DataKeyArray.cs
- Int64Animation.cs
- IIS7WorkerRequest.cs
- Rules.cs
- CodeGenerator.cs
- dataprotectionpermission.cs
- DataGridViewAccessibleObject.cs
- Odbc32.cs
- SqlDataSourceCommandParser.cs
- CryptoKeySecurity.cs
- WebHeaderCollection.cs
- WebDisplayNameAttribute.cs
- IdentitySection.cs
- JavaScriptString.cs
- ReverseInheritProperty.cs
- TableTextElementCollectionInternal.cs
- Divide.cs
- mansign.cs
- TimeStampChecker.cs
- HebrewNumber.cs
- InternalRelationshipCollection.cs
- IIS7UserPrincipal.cs
- nulltextcontainer.cs
- Triplet.cs
- HitTestFilterBehavior.cs
- WorkflowView.cs
- ContainerParaClient.cs
- SiteMapNodeItem.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- ListBoxItemAutomationPeer.cs
- FragmentNavigationEventArgs.cs
- XmlSchemaAttributeGroup.cs
- ClientBuildManager.cs
- _DomainName.cs
- BindingMAnagerBase.cs
- MemberMaps.cs
- MarkupObject.cs
- altserialization.cs
- ImageCollectionEditor.cs