Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / clr / src / ManagedLibraries / Security / System / Security / Cryptography / Xml / CipherData.cs / 1 / 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
- InheritanceRules.cs
- ConfigurationManagerInternalFactory.cs
- SlipBehavior.cs
- METAHEADER.cs
- XmlEncoding.cs
- InOutArgumentConverter.cs
- DbConnectionClosed.cs
- RenderData.cs
- DataGridViewCellConverter.cs
- UshortList2.cs
- MembershipSection.cs
- TextServicesProperty.cs
- RepeatInfo.cs
- NativeMethods.cs
- SHA1CryptoServiceProvider.cs
- GenericArgumentsUpdater.cs
- ToolBarTray.cs
- DoubleIndependentAnimationStorage.cs
- HealthMonitoringSectionHelper.cs
- TextBoxBase.cs
- OpCopier.cs
- XmlDownloadManager.cs
- MenuItem.cs
- AuthenticationModuleElement.cs
- ThrowHelper.cs
- SqlNodeTypeOperators.cs
- ElementNotAvailableException.cs
- FileDialog_Vista.cs
- RandomNumberGenerator.cs
- ConfigurationLocation.cs
- InstanceNormalEvent.cs
- TraceSection.cs
- PostBackOptions.cs
- CollectionChangedEventManager.cs
- TreeNodeCollection.cs
- WebReferenceCollection.cs
- ImageListUtils.cs
- TemplateKeyConverter.cs
- AdjustableArrowCap.cs
- InputBinding.cs
- BitVec.cs
- DataTableMappingCollection.cs
- PageBreakRecord.cs
- DataGridViewComponentPropertyGridSite.cs
- IisNotInstalledException.cs
- FlowDocumentPageViewerAutomationPeer.cs
- DbgCompiler.cs
- DataBoundControlAdapter.cs
- ActionMessageFilter.cs
- DirectoryNotFoundException.cs
- Interlocked.cs
- EdmToObjectNamespaceMap.cs
- LinkArea.cs
- HttpValueCollection.cs
- SqlBulkCopy.cs
- RegexStringValidator.cs
- TreeWalker.cs
- Collection.cs
- WebReferenceOptions.cs
- GestureRecognitionResult.cs
- VarRefManager.cs
- KnownBoxes.cs
- ApplicationBuildProvider.cs
- WinFormsComponentEditor.cs
- IpcClientManager.cs
- UrlMappingsModule.cs
- TableProviderWrapper.cs
- StringStorage.cs
- JournalEntryStack.cs
- FontFamily.cs
- SwitchLevelAttribute.cs
- FilteredDataSetHelper.cs
- AsyncOperationContext.cs
- StreamAsIStream.cs
- TextTreeInsertUndoUnit.cs
- PropVariant.cs
- WebResourceUtil.cs
- ItemAutomationPeer.cs
- MarshalByRefObject.cs
- OdbcFactory.cs
- DataSvcMapFile.cs
- SuppressIldasmAttribute.cs
- ResourceAssociationType.cs
- DocumentPageHost.cs
- SchemaElement.cs
- DataKey.cs
- ColumnHeaderConverter.cs
- VisualTreeHelper.cs
- AuthenticationServiceManager.cs
- XmlSchemaComplexContentExtension.cs
- PtsHelper.cs
- Padding.cs
- CompositeFontParser.cs
- PenContext.cs
- DataGridCellsPresenter.cs
- PageThemeBuildProvider.cs
- ColumnClickEvent.cs
- BinaryConverter.cs
- DoubleKeyFrameCollection.cs
- Faults.cs