Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / ManagedLibraries / Security / System / Security / Cryptography / Xml / CipherData.cs / 1305376 / 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
- SecurityRequiresReviewAttribute.cs
- DataKeyCollection.cs
- EventProvider.cs
- ELinqQueryState.cs
- StateMachineExecutionState.cs
- KeyConstraint.cs
- XmlArrayItemAttributes.cs
- DocumentReferenceCollection.cs
- OrderedHashRepartitionStream.cs
- CompilerCollection.cs
- EUCJPEncoding.cs
- TimeoutException.cs
- CodeGroup.cs
- HttpModulesSection.cs
- FirstMatchCodeGroup.cs
- SafeFileMappingHandle.cs
- EntityCommandDefinition.cs
- OpCodes.cs
- CollectionEditVerbManager.cs
- SendOperation.cs
- ImpersonationContext.cs
- DBSqlParserTableCollection.cs
- BooleanConverter.cs
- _ListenerRequestStream.cs
- IntSecurity.cs
- EventTrigger.cs
- CustomTypeDescriptor.cs
- MemberHolder.cs
- DeclaredTypeValidator.cs
- WeakReadOnlyCollection.cs
- Wizard.cs
- AddInContractAttribute.cs
- RequestCacheValidator.cs
- ContainerAction.cs
- ProxyGenerationError.cs
- CompositeFontInfo.cs
- SHA256.cs
- CharacterString.cs
- NotFiniteNumberException.cs
- SmtpFailedRecipientsException.cs
- BCryptHashAlgorithm.cs
- LineSegment.cs
- CrossAppDomainChannel.cs
- Pair.cs
- TextEditorDragDrop.cs
- EdmValidator.cs
- QueryNode.cs
- HtmlShimManager.cs
- EdmValidator.cs
- IntSecurity.cs
- CacheEntry.cs
- SafeWaitHandle.cs
- DecimalKeyFrameCollection.cs
- TypeSource.cs
- WebHttpSecurity.cs
- SetIterators.cs
- StatusBarAutomationPeer.cs
- UpdatePanelTriggerCollection.cs
- StringToken.cs
- DataGridViewCheckBoxColumn.cs
- CheckBoxBaseAdapter.cs
- TreeNodeSelectionProcessor.cs
- ApplicationFileCodeDomTreeGenerator.cs
- SqlCacheDependency.cs
- Rect.cs
- SrgsSubset.cs
- BuilderPropertyEntry.cs
- WebPartZoneBaseDesigner.cs
- DSASignatureFormatter.cs
- SqlDataSourceSummaryPanel.cs
- VerificationAttribute.cs
- GenericWebPart.cs
- LeafCellTreeNode.cs
- KeysConverter.cs
- ListenerElementsCollection.cs
- TableCell.cs
- MetadataExchangeClient.cs
- Group.cs
- DispatcherSynchronizationContext.cs
- PolyBezierSegment.cs
- DefaultTextStoreTextComposition.cs
- HttpPostedFileWrapper.cs
- HasCopySemanticsAttribute.cs
- DbBuffer.cs
- safemediahandle.cs
- DllNotFoundException.cs
- DataGridViewRowPostPaintEventArgs.cs
- AuditLog.cs
- Pair.cs
- AdjustableArrowCap.cs
- FixedSOMPageConstructor.cs
- WindowsSolidBrush.cs
- TabRenderer.cs
- ListDictionaryInternal.cs
- SQLMembershipProvider.cs
- HScrollBar.cs
- HtmlHead.cs
- dbdatarecord.cs
- keycontainerpermission.cs
- ObjectHandle.cs