Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / ManagedLibraries / Security / System / Security / Cryptography / Xml / CipherData.cs / 5 / CipherData.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// CipherData.cs
//
// This object implements the CipherData element.
//
// 04/01/2001
//
namespace System.Security.Cryptography.Xml
{
using System;
using System.Collections;
using System.Xml;
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CipherData {
private XmlElement m_cachedXml = null;
private CipherReference m_cipherReference = null;
private byte[] m_cipherValue = null;
public CipherData () {}
public CipherData (byte[] cipherValue) {
this.CipherValue = cipherValue;
}
public CipherData (CipherReference cipherReference) {
this.CipherReference = cipherReference;
}
private bool CacheValid {
get {
return (m_cachedXml != null);
}
}
public CipherReference CipherReference {
get { return m_cipherReference; }
set {
if (value == null)
throw new ArgumentNullException("value");
if (this.CipherValue != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherReference = value;
m_cachedXml = null;
}
}
public byte[] CipherValue {
get { return m_cipherValue; }
set {
if (value == null)
throw new ArgumentNullException("value");
if (this.CipherReference != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherValue = (byte[]) value.Clone();
m_cachedXml = null;
}
}
public XmlElement GetXml () {
if (CacheValid) return m_cachedXml;
XmlDocument document = new XmlDocument();
document.PreserveWhitespace = true;
return GetXml(document);
}
internal XmlElement GetXml (XmlDocument document) {
// Create the CipherData element
XmlElement cipherDataElement = (XmlElement)document.CreateElement("CipherData", EncryptedXml.XmlEncNamespaceUrl);
if (CipherValue != null) {
XmlElement cipherValueElement = document.CreateElement("CipherValue", EncryptedXml.XmlEncNamespaceUrl);
cipherValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(CipherValue)));
cipherDataElement.AppendChild(cipherValueElement);
} else {
// No CipherValue specified, see if there is a CipherReference
if (CipherReference == null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
cipherDataElement.AppendChild(CipherReference.GetXml(document));
}
return cipherDataElement;
}
public void LoadXml (XmlElement value) {
if (value == null)
throw new ArgumentNullException("value");
XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);
nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl);
XmlNode cipherValueNode = value.SelectSingleNode("enc:CipherValue", nsm);
XmlNode cipherReferenceNode = value.SelectSingleNode("enc:CipherReference", nsm);
if (cipherValueNode != null) {
if (cipherReferenceNode != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherValue = Convert.FromBase64String(Utils.DiscardWhiteSpaces(cipherValueNode.InnerText));
} else if (cipherReferenceNode != null) {
m_cipherReference = new CipherReference();
m_cipherReference.LoadXml((XmlElement) cipherReferenceNode);
} else {
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
}
// Save away the cached value
m_cachedXml = value;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
//
// CipherData.cs
//
// This object implements the CipherData element.
//
// 04/01/2001
//
namespace System.Security.Cryptography.Xml
{
using System;
using System.Collections;
using System.Xml;
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
public sealed class CipherData {
private XmlElement m_cachedXml = null;
private CipherReference m_cipherReference = null;
private byte[] m_cipherValue = null;
public CipherData () {}
public CipherData (byte[] cipherValue) {
this.CipherValue = cipherValue;
}
public CipherData (CipherReference cipherReference) {
this.CipherReference = cipherReference;
}
private bool CacheValid {
get {
return (m_cachedXml != null);
}
}
public CipherReference CipherReference {
get { return m_cipherReference; }
set {
if (value == null)
throw new ArgumentNullException("value");
if (this.CipherValue != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherReference = value;
m_cachedXml = null;
}
}
public byte[] CipherValue {
get { return m_cipherValue; }
set {
if (value == null)
throw new ArgumentNullException("value");
if (this.CipherReference != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherValue = (byte[]) value.Clone();
m_cachedXml = null;
}
}
public XmlElement GetXml () {
if (CacheValid) return m_cachedXml;
XmlDocument document = new XmlDocument();
document.PreserveWhitespace = true;
return GetXml(document);
}
internal XmlElement GetXml (XmlDocument document) {
// Create the CipherData element
XmlElement cipherDataElement = (XmlElement)document.CreateElement("CipherData", EncryptedXml.XmlEncNamespaceUrl);
if (CipherValue != null) {
XmlElement cipherValueElement = document.CreateElement("CipherValue", EncryptedXml.XmlEncNamespaceUrl);
cipherValueElement.AppendChild(document.CreateTextNode(Convert.ToBase64String(CipherValue)));
cipherDataElement.AppendChild(cipherValueElement);
} else {
// No CipherValue specified, see if there is a CipherReference
if (CipherReference == null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
cipherDataElement.AppendChild(CipherReference.GetXml(document));
}
return cipherDataElement;
}
public void LoadXml (XmlElement value) {
if (value == null)
throw new ArgumentNullException("value");
XmlNamespaceManager nsm = new XmlNamespaceManager(value.OwnerDocument.NameTable);
nsm.AddNamespace("enc", EncryptedXml.XmlEncNamespaceUrl);
XmlNode cipherValueNode = value.SelectSingleNode("enc:CipherValue", nsm);
XmlNode cipherReferenceNode = value.SelectSingleNode("enc:CipherReference", nsm);
if (cipherValueNode != null) {
if (cipherReferenceNode != null)
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
m_cipherValue = Convert.FromBase64String(Utils.DiscardWhiteSpaces(cipherValueNode.InnerText));
} else if (cipherReferenceNode != null) {
m_cipherReference = new CipherReference();
m_cipherReference.LoadXml((XmlElement) cipherReferenceNode);
} else {
throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_CipherValueElementRequired"));
}
// Save away the cached value
m_cachedXml = 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
- RelationshipEndMember.cs
- LogExtent.cs
- WindowsSpinner.cs
- AttachedPropertyInfo.cs
- NonSerializedAttribute.cs
- SqlBooleanizer.cs
- XamlTemplateSerializer.cs
- TogglePattern.cs
- MultiBindingExpression.cs
- AuthenticatingEventArgs.cs
- RenderContext.cs
- EventDrivenDesigner.cs
- StringKeyFrameCollection.cs
- VectorAnimation.cs
- TraceHwndHost.cs
- BindingElementExtensionElement.cs
- DbProviderFactoriesConfigurationHandler.cs
- StringReader.cs
- RuleRefElement.cs
- TypeSystem.cs
- MouseDevice.cs
- TabRenderer.cs
- HttpValueCollection.cs
- OleDbRowUpdatedEvent.cs
- RectAnimationClockResource.cs
- UserControlDesigner.cs
- CustomDictionarySources.cs
- XmlSchemaComplexType.cs
- SafeArrayTypeMismatchException.cs
- NetworkStream.cs
- LoginViewDesigner.cs
- WebPartRestoreVerb.cs
- SqlBulkCopyColumnMappingCollection.cs
- DefaultSerializationProviderAttribute.cs
- ContentDefinition.cs
- InputChannel.cs
- VisualTreeFlattener.cs
- HtmlContainerControl.cs
- ConnectionManagementElement.cs
- SqlRowUpdatedEvent.cs
- StandardBindingElementCollection.cs
- SafeEventLogWriteHandle.cs
- ExtenderHelpers.cs
- TableRow.cs
- PointF.cs
- TextLineResult.cs
- ComEventsMethod.cs
- FormViewDeleteEventArgs.cs
- DbConnectionClosed.cs
- CompilerScopeManager.cs
- Tool.cs
- DataObjectEventArgs.cs
- Root.cs
- SubMenuStyle.cs
- ProfileModule.cs
- IISUnsafeMethods.cs
- RsaElement.cs
- TreeNodeCollectionEditor.cs
- SessionPageStatePersister.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- NominalTypeEliminator.cs
- WebServicesDescriptionAttribute.cs
- ReliabilityContractAttribute.cs
- PseudoWebRequest.cs
- DataServiceResponse.cs
- ThousandthOfEmRealPoints.cs
- PageHandlerFactory.cs
- MemoryFailPoint.cs
- FixedSOMTableRow.cs
- Vector3DKeyFrameCollection.cs
- ListViewDeletedEventArgs.cs
- ParameterCollection.cs
- SafeUserTokenHandle.cs
- ContextMenuStrip.cs
- ChildDocumentBlock.cs
- ConfigurationStrings.cs
- TypeUtils.cs
- SQLMembershipProvider.cs
- comcontractssection.cs
- ProfessionalColors.cs
- EmbossBitmapEffect.cs
- XmlNullResolver.cs
- RandomNumberGenerator.cs
- DataRow.cs
- ClientBuildManagerCallback.cs
- CollectionsUtil.cs
- ReadOnlyNameValueCollection.cs
- DBSqlParser.cs
- CryptoKeySecurity.cs
- SQlBooleanStorage.cs
- CompleteWizardStep.cs
- IntMinMaxAggregationOperator.cs
- TransformerConfigurationWizardBase.cs
- AlternateViewCollection.cs
- Polyline.cs
- NavigationCommands.cs
- ProtectedProviderSettings.cs
- CompilerLocalReference.cs
- StreamReader.cs
- GroupBox.cs