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
- XmlHierarchyData.cs
- TrustManagerMoreInformation.cs
- TakeOrSkipWhileQueryOperator.cs
- RayMeshGeometry3DHitTestResult.cs
- RedirectionProxy.cs
- ADMembershipUser.cs
- HTTPNotFoundHandler.cs
- EmptyReadOnlyDictionaryInternal.cs
- WebBrowser.cs
- HtmlShim.cs
- GroupedContextMenuStrip.cs
- MsmqBindingFilter.cs
- NameValueSectionHandler.cs
- InvalidWMPVersionException.cs
- MDIControlStrip.cs
- DbConnectionClosed.cs
- PermissionSetEnumerator.cs
- RelationshipWrapper.cs
- DispatcherOperation.cs
- StringStorage.cs
- Profiler.cs
- XmlKeywords.cs
- ParallelDesigner.cs
- TableRowCollection.cs
- Decimal.cs
- ObjectStateEntryDbDataRecord.cs
- CodeDomDesignerLoader.cs
- QilDataSource.cs
- AttributeProviderAttribute.cs
- PackWebResponse.cs
- BindingObserver.cs
- GenericXmlSecurityToken.cs
- HtmlCommandAdapter.cs
- CompilationSection.cs
- Identity.cs
- TriggerCollection.cs
- SqlErrorCollection.cs
- FlowLayoutPanel.cs
- XXXInfos.cs
- HotSpot.cs
- CharacterHit.cs
- ChtmlCommandAdapter.cs
- ScriptServiceAttribute.cs
- ApplyTemplatesAction.cs
- VsPropertyGrid.cs
- DataControlFieldCell.cs
- _LazyAsyncResult.cs
- SqlGatherConsumedAliases.cs
- SizeAnimationBase.cs
- TransportationConfigurationTypeInstallComponent.cs
- HtmlUtf8RawTextWriter.cs
- DataProtection.cs
- _FtpControlStream.cs
- MsmqHostedTransportConfiguration.cs
- MatrixTransform3D.cs
- RightsManagementEncryptedStream.cs
- messageonlyhwndwrapper.cs
- LockRenewalTask.cs
- Html32TextWriter.cs
- SubMenuStyleCollection.cs
- DataGridHelper.cs
- SafeRsaProviderHandle.cs
- QilName.cs
- ColorTransform.cs
- ControlBuilderAttribute.cs
- PanelContainerDesigner.cs
- Screen.cs
- FontSource.cs
- MenuAutoFormat.cs
- RawStylusInputCustomDataList.cs
- QueryContinueDragEvent.cs
- CustomAssemblyResolver.cs
- CompiledXpathExpr.cs
- StylusPlugInCollection.cs
- HtmlControlPersistable.cs
- XsltQilFactory.cs
- RightsManagementEncryptedStream.cs
- ToolStripPanelRenderEventArgs.cs
- IndexedSelectQueryOperator.cs
- SqlSupersetValidator.cs
- _NegoStream.cs
- HighlightVisual.cs
- OperandQuery.cs
- X509CertificateChain.cs
- FaultHandlingFilter.cs
- EncoderExceptionFallback.cs
- ValidationException.cs
- EdmItemCollection.cs
- PanelDesigner.cs
- SoapExtensionStream.cs
- AudioFormatConverter.cs
- RIPEMD160Managed.cs
- ButtonField.cs
- MouseWheelEventArgs.cs
- SplineKeyFrames.cs
- HwndKeyboardInputProvider.cs
- DataGridViewRowCollection.cs
- AnonymousIdentificationSection.cs
- MembershipSection.cs
- documentsequencetextcontainer.cs