Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / EncryptedKey.cs / 1 / EncryptedKey.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.IO; using System.Security.Cryptography; using System.Text; using System.Xml; sealed class EncryptedKey : EncryptedType { internal static readonly XmlDictionaryString CarriedKeyElementName = XD.XmlEncryptionDictionary.CarriedKeyName; internal static readonly XmlDictionaryString ElementName = XD.XmlEncryptionDictionary.EncryptedKey; internal static readonly XmlDictionaryString RecipientAttribute = XD.XmlEncryptionDictionary.Recipient; string carriedKeyName; string recipient; ReferenceList referenceList; byte[] wrappedKey; public string CarriedKeyName { get { return this.carriedKeyName; } set { this.carriedKeyName = value; } } public string Recipient { get { return this.recipient; } set { this.recipient = value; } } public ReferenceList ReferenceList { get { return this.referenceList; } set { this.referenceList = value; } } protected override XmlDictionaryString OpeningElementName { get { return ElementName; } } protected override void ForceEncryption() { // no work to be done here since, unlike bulk encryption, key wrapping is done eagerly } public byte[] GetWrappedKey() { if (this.State == EncryptionState.New) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BadEncryptionState))); } return this.wrappedKey; } public void SetUpKeyWrap(byte[] wrappedKey) { if (this.State != EncryptionState.New) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BadEncryptionState))); } if (wrappedKey == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("wrappedKey"); } this.wrappedKey = wrappedKey; this.State = EncryptionState.Encrypted; } protected override void ReadAdditionalAttributes(XmlDictionaryReader reader) { this.recipient = reader.GetAttribute(RecipientAttribute, null); } protected override void ReadAdditionalElements(XmlDictionaryReader reader) { if (reader.IsStartElement(ReferenceList.ElementName, EncryptedType.NamespaceUri)) { this.referenceList = new ReferenceList(); this.referenceList.ReadFrom(reader); } if (reader.IsStartElement(CarriedKeyElementName, EncryptedType.NamespaceUri)) { reader.ReadStartElement(CarriedKeyElementName, EncryptedType.NamespaceUri); this.carriedKeyName = reader.ReadString(); reader.ReadEndElement(); } } protected override void ReadCipherData(XmlDictionaryReader reader) { this.wrappedKey = reader.ReadContentAsBase64(); } protected override void ReadCipherData(XmlDictionaryReader reader, long maxBufferSize) { this.wrappedKey = SecurityUtils.ReadContentAsBase64(reader, maxBufferSize); } protected override void WriteAdditionalAttributes(XmlDictionaryWriter writer) { if (this.recipient != null) { writer.WriteAttributeString(RecipientAttribute, null, this.recipient); } } protected override void WriteAdditionalElements(XmlDictionaryWriter writer) { if (this.carriedKeyName != null) { writer.WriteStartElement(CarriedKeyElementName, EncryptedType.NamespaceUri); writer.WriteString(this.carriedKeyName); writer.WriteEndElement(); // CarriedKeyName } if (this.referenceList != null) { this.referenceList.WriteTo(writer, ServiceModelDictionaryManager.Instance); } } protected override void WriteCipherData(XmlDictionaryWriter writer) { writer.WriteBase64(this.wrappedKey, 0, this.wrappedKey.Length); } } } // 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
- XmlnsPrefixAttribute.cs
- TreeNodeCollection.cs
- FramingChannels.cs
- IBuiltInEvidence.cs
- DeferredElementTreeState.cs
- XmlSchemaGroupRef.cs
- MdiWindowListItemConverter.cs
- RelatedCurrencyManager.cs
- MulticastOption.cs
- WebPartMovingEventArgs.cs
- EraserBehavior.cs
- DeferredElementTreeState.cs
- serverconfig.cs
- XhtmlBasicCalendarAdapter.cs
- ListViewInsertEventArgs.cs
- SharedStatics.cs
- DataStreamFromComStream.cs
- PrePrepareMethodAttribute.cs
- BindingList.cs
- VisualBrush.cs
- AutomationAttributeInfo.cs
- ListViewDesigner.cs
- ProviderCommandInfoUtils.cs
- DateTimeOffsetStorage.cs
- SchemaTypeEmitter.cs
- EntityDescriptor.cs
- CheckBox.cs
- _SSPIWrapper.cs
- KeyPressEvent.cs
- ProjectionAnalyzer.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- ProcessHostServerConfig.cs
- PropertyNames.cs
- HatchBrush.cs
- SafeCryptoHandles.cs
- LayoutTableCell.cs
- dataobject.cs
- BitmapMetadata.cs
- AppDomainProtocolHandler.cs
- WindowsFormsLinkLabel.cs
- SinglePageViewer.cs
- AssertFilter.cs
- InternalBufferOverflowException.cs
- FixUpCollection.cs
- ServiceEndpointElementCollection.cs
- DescendantOverDescendantQuery.cs
- safex509handles.cs
- DataGridViewControlCollection.cs
- CheckedListBox.cs
- ControlBuilder.cs
- CharAnimationUsingKeyFrames.cs
- OleDbMetaDataFactory.cs
- Thumb.cs
- EnumValidator.cs
- CopyNodeSetAction.cs
- Executor.cs
- SqlDataSource.cs
- SafeNativeMethodsOther.cs
- WebPartDisplayModeCancelEventArgs.cs
- CallSite.cs
- ISFClipboardData.cs
- FreezableCollection.cs
- DataGridColumnStyleMappingNameEditor.cs
- ThreadExceptionDialog.cs
- BulletDecorator.cs
- GridViewSortEventArgs.cs
- UnconditionalPolicy.cs
- WebConfigManager.cs
- Utility.cs
- DataSpaceManager.cs
- UIElementParaClient.cs
- PKCS1MaskGenerationMethod.cs
- RunWorkerCompletedEventArgs.cs
- WindowInteractionStateTracker.cs
- SimpleApplicationHost.cs
- ValueChangedEventManager.cs
- ChildTable.cs
- StrictAndMessageFilter.cs
- SharedStatics.cs
- SHA1CryptoServiceProvider.cs
- CqlParser.cs
- DefaultValueAttribute.cs
- ReadOnlyCollection.cs
- ToolStripGrip.cs
- UnauthorizedWebPart.cs
- StaticTextPointer.cs
- RawUIStateInputReport.cs
- EntityConnectionStringBuilder.cs
- ProgressBarRenderer.cs
- HtmlAnchor.cs
- ExpandSegment.cs
- DataGridViewTextBoxEditingControl.cs
- FormViewCommandEventArgs.cs
- EmptyEnumerator.cs
- CompositeDuplexElement.cs
- DoubleAnimation.cs
- Cursor.cs
- MimeXmlReflector.cs
- AttributeEmitter.cs
- CookielessHelper.cs