Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- HeaderCollection.cs
- FrameworkElementAutomationPeer.cs
- LambdaCompiler.Expressions.cs
- FontCacheUtil.cs
- CalendarAutomationPeer.cs
- CookieProtection.cs
- SettingsPropertyNotFoundException.cs
- CollectionViewGroupRoot.cs
- ProcessProtocolHandler.cs
- ThreadAttributes.cs
- IssuanceLicense.cs
- WebConfigurationFileMap.cs
- FileLevelControlBuilderAttribute.cs
- UriParserTemplates.cs
- ParamArrayAttribute.cs
- WindowsScrollBar.cs
- UnsafeNativeMethods.cs
- HttpWebResponse.cs
- AutomationElement.cs
- MessageCredentialType.cs
- followingquery.cs
- WindowsTab.cs
- Grant.cs
- jithelpers.cs
- UpdateTracker.cs
- recordstatefactory.cs
- ApplicationTrust.cs
- PropertySegmentSerializer.cs
- dbenumerator.cs
- PerspectiveCamera.cs
- WorkflowItemsPresenter.cs
- ObjectListSelectEventArgs.cs
- EventHandlersStore.cs
- MarkupObject.cs
- SqlClientWrapperSmiStream.cs
- XmlSchemaGroupRef.cs
- XamlPointCollectionSerializer.cs
- ToolStripRenderer.cs
- FixedSOMLineRanges.cs
- KeyPullup.cs
- EventSource.cs
- Rotation3D.cs
- UserPreferenceChangedEventArgs.cs
- ProgressBar.cs
- SoapSchemaMember.cs
- DocumentPageTextView.cs
- SamlDelegatingWriter.cs
- Evidence.cs
- QueryRewriter.cs
- Converter.cs
- TextStore.cs
- BuildProviderCollection.cs
- DefinitionUpdate.cs
- XmlNotation.cs
- RootBrowserWindowAutomationPeer.cs
- XhtmlBasicImageAdapter.cs
- PointLight.cs
- TransactionProtocolConverter.cs
- HostedHttpRequestAsyncResult.cs
- DocumentPageHost.cs
- DirectoryRedirect.cs
- ContentIterators.cs
- VirtualPathProvider.cs
- Queue.cs
- LinkConverter.cs
- TrackingWorkflowEventArgs.cs
- EntityClassGenerator.cs
- TransformerInfo.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- MobileCapabilities.cs
- XmlCharacterData.cs
- Attributes.cs
- Rect.cs
- Camera.cs
- VectorConverter.cs
- DBConnectionString.cs
- HttpFileCollection.cs
- DocumentReference.cs
- EventLogPropertySelector.cs
- AuthStoreRoleProvider.cs
- TransactionFilter.cs
- Utils.cs
- SqlClientMetaDataCollectionNames.cs
- FactoryId.cs
- OciHandle.cs
- NativeMethods.cs
- DecoderReplacementFallback.cs
- Model3D.cs
- DiagnosticsConfigurationHandler.cs
- PlatformCulture.cs
- ContentElement.cs
- EllipseGeometry.cs
- _LoggingObject.cs
- ReflectionUtil.cs
- PropertyMetadata.cs
- URLIdentityPermission.cs
- DoubleAnimation.cs
- LinqTreeNodeEvaluator.cs
- AddInActivator.cs
- VerificationAttribute.cs