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
- TriggerActionCollection.cs
- WindowsRebar.cs
- XmlElementAttributes.cs
- TextSelectionHighlightLayer.cs
- SortDescription.cs
- HttpBrowserCapabilitiesBase.cs
- TreeView.cs
- ScopelessEnumAttribute.cs
- ConfigurationValidatorBase.cs
- WebRequestModuleElementCollection.cs
- WorkflowApplication.cs
- TextRangeEditTables.cs
- TextEditor.cs
- AppDomain.cs
- MailDefinition.cs
- CodeExpressionCollection.cs
- XmlReturnReader.cs
- Pool.cs
- SqlDeflator.cs
- SchemaExporter.cs
- Drawing.cs
- CompositeKey.cs
- SizeAnimationBase.cs
- StringAnimationUsingKeyFrames.cs
- TextViewBase.cs
- Form.cs
- Serializer.cs
- ImageField.cs
- UTF8Encoding.cs
- ByteStorage.cs
- WebPartRestoreVerb.cs
- AsmxEndpointPickerExtension.cs
- XmlFormatReaderGenerator.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- PagePropertiesChangingEventArgs.cs
- ListBindingHelper.cs
- OrthographicCamera.cs
- _TimerThread.cs
- SqlDataRecord.cs
- COM2Enum.cs
- SchemaObjectWriter.cs
- DesignTimeData.cs
- SchemaImporterExtensionElementCollection.cs
- WorkflowStateRollbackService.cs
- BaseCollection.cs
- ErrorReporting.cs
- Queue.cs
- ClientSponsor.cs
- LinkArea.cs
- SynchronizationContext.cs
- EventDescriptorCollection.cs
- Transform3D.cs
- CapabilitiesAssignment.cs
- Array.cs
- FixedTextView.cs
- ISessionStateStore.cs
- ScrollProperties.cs
- ProxyHwnd.cs
- DependencyObjectProvider.cs
- XmlSchemaAnnotated.cs
- QueryExpr.cs
- XmlReaderSettings.cs
- CounterSample.cs
- PersonalizationStateInfoCollection.cs
- SystemTcpStatistics.cs
- SqlTypeConverter.cs
- BaseParagraph.cs
- PaperSource.cs
- IntSecurity.cs
- OdbcConnection.cs
- TreeNodeBindingCollection.cs
- CheckBoxAutomationPeer.cs
- OdbcConnection.cs
- RangeBase.cs
- Encoding.cs
- SchemaElementLookUpTableEnumerator.cs
- GenericTextProperties.cs
- HttpListenerRequest.cs
- BitmapPalettes.cs
- DataViewListener.cs
- ConsoleCancelEventArgs.cs
- SchemaElement.cs
- ObjectDataSourceView.cs
- Wildcard.cs
- xamlnodes.cs
- XmlDataSourceNodeDescriptor.cs
- GradientStop.cs
- DBConcurrencyException.cs
- ClientScriptManager.cs
- RawStylusInputCustomDataList.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- TextTreeTextBlock.cs
- SecurityKeyUsage.cs
- TextEffect.cs
- InputBindingCollection.cs
- HtmlElementErrorEventArgs.cs
- TraceLog.cs
- XPathDescendantIterator.cs
- GroupAggregateExpr.cs
- DocobjHost.cs