Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / EncryptedType.cs / 1 / EncryptedType.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.IO; using System.ServiceModel.Channels; using System.ServiceModel; using System.IdentityModel.Tokens; using System.IdentityModel.Selectors; using System.Security.Cryptography; using System.Text; using System.Xml; using DictionaryManager = System.IdentityModel.DictionaryManager; using SignedXml = System.IdentityModel.SignedXml; using ISecurityElement = System.IdentityModel.ISecurityElement; abstract class EncryptedType : ISecurityElement { internal static readonly XmlDictionaryString NamespaceUri = XD.XmlEncryptionDictionary.Namespace; internal static readonly XmlDictionaryString EncodingAttribute = XD.XmlEncryptionDictionary.Encoding; internal static readonly XmlDictionaryString MimeTypeAttribute = XD.XmlEncryptionDictionary.MimeType; internal static readonly XmlDictionaryString TypeAttribute = XD.XmlEncryptionDictionary.Type; internal static readonly XmlDictionaryString CipherDataElementName = XD.XmlEncryptionDictionary.CipherData; internal static readonly XmlDictionaryString CipherValueElementName = XD.XmlEncryptionDictionary.CipherValue; string encoding; EncryptionMethodElement encryptionMethod; string id; string wsuId; SecurityKeyIdentifier keyIdentifier; string mimeType; EncryptionState state; string type; SecurityTokenSerializer tokenSerializer; protected EncryptedType() { this.encryptionMethod.Init(); this.state = EncryptionState.New; this.tokenSerializer = SecurityStandardsManager.DefaultInstance.SecurityTokenSerializer; } public string Encoding { get { return this.encoding; } set { this.encoding = value; } } public string EncryptionMethod { get { return this.encryptionMethod.algorithm; } set { this.encryptionMethod.algorithm = value; } } public XmlDictionaryString EncryptionMethodDictionaryString { get { return this.encryptionMethod.algorithmDictionaryString; } set { this.encryptionMethod.algorithmDictionaryString = value; } } public bool HasId { get { return true; } } public string Id { get { return this.id; } set { this.id = value; } } public string WsuId { get { return this.wsuId; } set { this.wsuId = value; } } public SecurityKeyIdentifier KeyIdentifier { get { return this.keyIdentifier; } set { this.keyIdentifier = value; } } public string MimeType { get { return this.mimeType; } set { this.mimeType = value; } } public string Type { get { return this.type; } set { this.type = value; } } protected abstract XmlDictionaryString OpeningElementName { get; } protected EncryptionState State { get { return this.state; } set { this.state = value; } } public SecurityTokenSerializer SecurityTokenSerializer { get { return this.tokenSerializer; } set { this.tokenSerializer = value ?? WSSecurityTokenSerializer.DefaultInstance; } } protected abstract void ForceEncryption(); protected virtual void ReadAdditionalAttributes(XmlDictionaryReader reader) { } protected virtual void ReadAdditionalElements(XmlDictionaryReader reader) { } protected abstract void ReadCipherData(XmlDictionaryReader reader); protected abstract void ReadCipherData(XmlDictionaryReader reader, long maxBufferSize); public void ReadFrom(XmlReader reader) { ReadFrom(reader, 0); } public void ReadFrom(XmlDictionaryReader reader) { ReadFrom(reader, 0); } public void ReadFrom(XmlReader reader, long maxBufferSize) { ReadFrom(XmlDictionaryReader.CreateDictionaryReader(reader), maxBufferSize); } public void ReadFrom(XmlDictionaryReader reader, long maxBufferSize) { ValidateReadState(); reader.MoveToStartElement(OpeningElementName, NamespaceUri); this.encoding = reader.GetAttribute(EncodingAttribute, null); this.id = reader.GetAttribute(XD.XmlEncryptionDictionary.Id, null) ?? SecurityUniqueId.Create().Value; this.wsuId = reader.GetAttribute(XD.XmlEncryptionDictionary.Id, XD.UtilityDictionary.Namespace) ?? SecurityUniqueId.Create().Value; this.mimeType = reader.GetAttribute(MimeTypeAttribute, null); this.type = reader.GetAttribute(TypeAttribute, null); ReadAdditionalAttributes(reader); reader.Read(); if (reader.IsStartElement(EncryptionMethodElement.ElementName, NamespaceUri)) { this.encryptionMethod.ReadFrom(reader); } if (this.tokenSerializer.CanReadKeyIdentifier(reader)) { this.KeyIdentifier = this.tokenSerializer.ReadKeyIdentifier(reader); } reader.ReadStartElement(CipherDataElementName, EncryptedType.NamespaceUri); reader.ReadStartElement(CipherValueElementName, EncryptedType.NamespaceUri); if (maxBufferSize == 0) ReadCipherData(reader); else ReadCipherData(reader, maxBufferSize); reader.ReadEndElement(); // CipherValue reader.ReadEndElement(); // CipherData ReadAdditionalElements(reader); reader.ReadEndElement(); // OpeningElementName this.State = EncryptionState.Read; } protected virtual void WriteAdditionalAttributes(XmlDictionaryWriter writer) { } protected virtual void WriteAdditionalElements(XmlDictionaryWriter writer) { } protected abstract void WriteCipherData(XmlDictionaryWriter writer); public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } ValidateWriteState(); writer.WriteStartElement(XmlEncryptionStrings.Prefix, this.OpeningElementName, NamespaceUri); if (this.id != null && this.id.Length != 0) { writer.WriteAttributeString(XD.XmlEncryptionDictionary.Id, null, this.Id); } if (this.type != null) { writer.WriteAttributeString(TypeAttribute, null, this.Type); } if (this.mimeType != null) { writer.WriteAttributeString(MimeTypeAttribute, null, this.MimeType); } if (this.encoding != null) { writer.WriteAttributeString(EncodingAttribute, null, this.Encoding); } WriteAdditionalAttributes(writer); if (this.encryptionMethod.algorithm != null) { this.encryptionMethod.WriteTo(writer); } if (this.KeyIdentifier != null) { this.tokenSerializer.WriteKeyIdentifier(writer, this.KeyIdentifier); } writer.WriteStartElement(CipherDataElementName, NamespaceUri); writer.WriteStartElement(CipherValueElementName, NamespaceUri); WriteCipherData(writer); writer.WriteEndElement(); // CipherValue writer.WriteEndElement(); // CipherData WriteAdditionalElements(writer); writer.WriteEndElement(); // OpeningElementName } void ValidateReadState() { if (this.State != EncryptionState.New) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.BadEncryptionState))); } } void ValidateWriteState() { if (this.State == EncryptionState.EncryptionSetup) { ForceEncryption(); } else if (this.State == EncryptionState.New) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.BadEncryptionState))); } } protected enum EncryptionState { New, Read, DecryptionSetup, Decrypted, EncryptionSetup, Encrypted } struct EncryptionMethodElement { internal string algorithm; internal XmlDictionaryString algorithmDictionaryString; internal static readonly XmlDictionaryString ElementName = XD.XmlEncryptionDictionary.EncryptionMethod; public void Init() { this.algorithm = null; } public void ReadFrom(XmlDictionaryReader reader) { reader.MoveToStartElement(ElementName, XD.XmlEncryptionDictionary.Namespace); bool isEmptyElement = reader.IsEmptyElement; this.algorithm = reader.GetAttribute(XD.XmlSignatureDictionary.Algorithm, null); if (this.algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException( SR.GetString(SR.RequiredAttributeMissing, XD.XmlSignatureDictionary.Algorithm.Value, ElementName.Value))); } reader.Read(); if (!isEmptyElement) { while (reader.IsStartElement()) { reader.Skip(); } reader.ReadEndElement(); } } public void WriteTo(XmlDictionaryWriter writer) { writer.WriteStartElement(XmlEncryptionStrings.Prefix, ElementName, XD.XmlEncryptionDictionary.Namespace); if (this.algorithmDictionaryString != null) { writer.WriteStartAttribute(XD.XmlSignatureDictionary.Algorithm, null); writer.WriteString(this.algorithmDictionaryString); writer.WriteEndAttribute(); } else { writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, this.algorithm); } if (this.algorithm == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value) { writer.WriteStartElement(XmlSignatureStrings.Prefix, XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace); writer.WriteStartAttribute(XD.XmlSignatureDictionary.Algorithm, null); writer.WriteString(XD.SecurityAlgorithmDictionary.Sha1Digest); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteEndElement(); // EncryptionMethod } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ViewCellSlot.cs
- SoapAttributeOverrides.cs
- unsafenativemethodsother.cs
- CleanUpVirtualizedItemEventArgs.cs
- LicenseContext.cs
- SeverityFilter.cs
- CodeFieldReferenceExpression.cs
- DictionaryContent.cs
- UnsafeNetInfoNativeMethods.cs
- TextBox.cs
- CharConverter.cs
- SpellCheck.cs
- BaseServiceProvider.cs
- QuadraticBezierSegment.cs
- BitmapEffect.cs
- CTreeGenerator.cs
- RangeExpression.cs
- GenericTypeParameterBuilder.cs
- SelectionProviderWrapper.cs
- ClientTargetCollection.cs
- ConvertEvent.cs
- GetLastErrorDetailsRequest.cs
- WindowsSspiNegotiation.cs
- BCryptHashAlgorithm.cs
- HttpFileCollection.cs
- RadialGradientBrush.cs
- DBBindings.cs
- MSAAEventDispatcher.cs
- MultipleViewPattern.cs
- DataGridViewTextBoxEditingControl.cs
- DbException.cs
- ConnectionStringsExpressionEditor.cs
- ActiveXContainer.cs
- TransformPattern.cs
- SerializationIncompleteException.cs
- PersonalizableTypeEntry.cs
- ApplicationServicesHostFactory.cs
- CriticalHandle.cs
- DropDownButton.cs
- SecurityKeyType.cs
- SubclassTypeValidator.cs
- SizeAnimation.cs
- GridViewHeaderRowPresenter.cs
- HttpCapabilitiesSectionHandler.cs
- SoapAttributeOverrides.cs
- ArrayConverter.cs
- ValueTable.cs
- EntityDataSourceQueryBuilder.cs
- UserControlBuildProvider.cs
- WebPartConnectionsCloseVerb.cs
- PartialCachingControl.cs
- ZipQueryOperator.cs
- EmbossBitmapEffect.cs
- formatter.cs
- MessageQueueTransaction.cs
- ISSmlParser.cs
- DataSourceGroupCollection.cs
- BindingFormattingDialog.cs
- AttachedPropertyMethodSelector.cs
- WmlLiteralTextAdapter.cs
- XmlQueryTypeFactory.cs
- ListViewUpdatedEventArgs.cs
- UIElement3D.cs
- ContextBase.cs
- HwndAppCommandInputProvider.cs
- MenuScrollingVisibilityConverter.cs
- NamedElement.cs
- XmlElement.cs
- StrokeCollectionConverter.cs
- PagesChangedEventArgs.cs
- CommandEventArgs.cs
- EmptyElement.cs
- IOException.cs
- ComponentEditorForm.cs
- BevelBitmapEffect.cs
- FontCacheLogic.cs
- InvokePatternIdentifiers.cs
- ApplicationGesture.cs
- ByteConverter.cs
- BadImageFormatException.cs
- OletxEnlistment.cs
- Point.cs
- LinqDataSourceSelectEventArgs.cs
- PropertyMapper.cs
- DiscreteKeyFrames.cs
- BreakRecordTable.cs
- QilCloneVisitor.cs
- PathFigureCollection.cs
- UnaryNode.cs
- InternalPermissions.cs
- HostedTransportConfigurationManager.cs
- StylusPlugInCollection.cs
- ContainerSelectorGlyph.cs
- ConnectionProviderAttribute.cs
- Int32KeyFrameCollection.cs
- DataControlReferenceCollection.cs
- BitmapCodecInfo.cs
- EventManager.cs
- AssemblyNameEqualityComparer.cs
- RegistryPermission.cs