Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / EncryptedData.cs / 1 / EncryptedData.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.Security.Cryptography; using System.ServiceModel.Channels; using System.Xml; class EncryptedData : EncryptedType { internal static readonly XmlDictionaryString ElementName = XD.XmlEncryptionDictionary.EncryptedData; internal static readonly string ElementType = XmlEncryptionStrings.ElementType; internal static readonly string ContentType = XmlEncryptionStrings.ContentType; SymmetricAlgorithm algorithm; byte[] decryptedBuffer; ArraySegmentbuffer; byte[] iv; byte[] cipherText; protected override XmlDictionaryString OpeningElementName { get { return ElementName; } } void EnsureDecryptionSet() { if (this.State == EncryptionState.DecryptionSetup) { SetPlainText(); } else if (this.State != EncryptionState.Decrypted) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.BadEncryptionState))); } } protected override void ForceEncryption() { CryptoHelper.GenerateIVAndEncrypt(this.algorithm, this.buffer, out this.iv, out this.cipherText); this.State = EncryptionState.Encrypted; this.buffer = new ArraySegment (CryptoHelper.EmptyBuffer); } public byte[] GetDecryptedBuffer() { EnsureDecryptionSet(); return this.decryptedBuffer; } protected override void ReadCipherData(XmlDictionaryReader reader) { this.cipherText = reader.ReadContentAsBase64(); } protected override void ReadCipherData(XmlDictionaryReader reader, long maxBufferSize) { this.cipherText = SecurityUtils.ReadContentAsBase64(reader, maxBufferSize); } void SetPlainText() { this.decryptedBuffer = CryptoHelper.ExtractIVAndDecrypt(this.algorithm, this.cipherText, 0, this.cipherText.Length); this.State = EncryptionState.Decrypted; } public void SetUpDecryption(SymmetricAlgorithm algorithm) { if (this.State != EncryptionState.Read) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.BadEncryptionState))); } if (algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("algorithm"); } this.algorithm = algorithm; this.State = EncryptionState.DecryptionSetup; } public void SetUpEncryption(SymmetricAlgorithm algorithm, ArraySegment buffer) { if (this.State != EncryptionState.New) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.BadEncryptionState))); } if (algorithm == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("algorithm"); } this.algorithm = algorithm; this.buffer = buffer; this.State = EncryptionState.EncryptionSetup; } protected override void WriteCipherData(XmlDictionaryWriter writer) { writer.WriteBase64(this.iv, 0, this.iv.Length); writer.WriteBase64(this.cipherText, 0, this.cipherText.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
- DataContract.cs
- ApplicationFileCodeDomTreeGenerator.cs
- Size3DConverter.cs
- ObjectDataSourceFilteringEventArgs.cs
- ArgumentValidation.cs
- followingsibling.cs
- PeoplePickerWrapper.cs
- FixUpCollection.cs
- TypographyProperties.cs
- WebPartCancelEventArgs.cs
- ICollection.cs
- XmlSchemaObject.cs
- StateMachineExecutionState.cs
- CmsInterop.cs
- PointHitTestParameters.cs
- WinFormsSecurity.cs
- ComponentManagerBroker.cs
- ChameleonKey.cs
- CharEntityEncoderFallback.cs
- Hashtable.cs
- CommandHelpers.cs
- CompositeCollectionView.cs
- TabControl.cs
- MessageEventSubscriptionService.cs
- ColorAnimationBase.cs
- SynthesizerStateChangedEventArgs.cs
- CompilationUtil.cs
- Rectangle.cs
- ListItemsCollectionEditor.cs
- XmlSchemaInfo.cs
- SignedInfo.cs
- SessionViewState.cs
- PagerSettings.cs
- XmlByteStreamReader.cs
- ToolStripOverflowButton.cs
- FileRecordSequenceCompletedAsyncResult.cs
- TrackingStringDictionary.cs
- SoapInteropTypes.cs
- Stack.cs
- AnimationClock.cs
- ComplexType.cs
- Publisher.cs
- DataBindingExpressionBuilder.cs
- ExtractedStateEntry.cs
- TypeLibConverter.cs
- Descriptor.cs
- ObjectIDGenerator.cs
- ElementHost.cs
- ContentOperations.cs
- CorrelationManager.cs
- EncryptionUtility.cs
- Marshal.cs
- TransformGroup.cs
- XmlQualifiedNameTest.cs
- ColorAnimation.cs
- ListViewSortEventArgs.cs
- ToolboxItemFilterAttribute.cs
- HtmlInputPassword.cs
- BuildManagerHost.cs
- SqlLiftWhereClauses.cs
- WebPartEditorCancelVerb.cs
- ScrollChrome.cs
- HTMLTextWriter.cs
- UnauthorizedAccessException.cs
- PrimitiveSchema.cs
- BitmapData.cs
- UICuesEvent.cs
- AuthorizationPolicyTypeElement.cs
- Parameter.cs
- RoutedUICommand.cs
- DrawingVisualDrawingContext.cs
- StructuralType.cs
- IBuiltInEvidence.cs
- HybridDictionary.cs
- TcpSocketManager.cs
- DbConnectionInternal.cs
- ReaderContextStackData.cs
- XamlTreeBuilder.cs
- XmlImplementation.cs
- ConvertersCollection.cs
- DataGridHelper.cs
- LayoutUtils.cs
- JsonFormatReaderGenerator.cs
- VirtualPathUtility.cs
- PageSetupDialog.cs
- InstanceNotReadyException.cs
- ContextMarshalException.cs
- CodeRemoveEventStatement.cs
- WeakReferenceEnumerator.cs
- DataRowChangeEvent.cs
- Convert.cs
- DispatcherExceptionFilterEventArgs.cs
- DataTableMappingCollection.cs
- XmlSchemaSimpleContent.cs
- StringKeyFrameCollection.cs
- ClientConfigurationHost.cs
- SerializationHelper.cs
- ViewStateException.cs
- DeclarativeCatalogPartDesigner.cs
- FileSystemEventArgs.cs