Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / DataProtectionSecurityStateEncoder.cs / 1 / DataProtectionSecurityStateEncoder.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Text;
using System.Security.Cryptography;
public class DataProtectionSecurityStateEncoder : SecurityStateEncoder
{
byte[] entropy;
bool useCurrentUserProtectionScope;
public DataProtectionSecurityStateEncoder()
: this(true)
{
// empty
}
public DataProtectionSecurityStateEncoder(bool useCurrentUserProtectionScope)
: this(useCurrentUserProtectionScope, null)
{ }
public DataProtectionSecurityStateEncoder(bool useCurrentUserProtectionScope, byte[] entropy)
{
this.useCurrentUserProtectionScope = useCurrentUserProtectionScope;
if (entropy == null)
{
this.entropy = null;
}
else
{
this.entropy = DiagnosticUtility.Utility.AllocateByteArray(entropy.Length);
Buffer.BlockCopy(entropy, 0, this.entropy, 0, entropy.Length);
}
}
public bool UseCurrentUserProtectionScope
{
get
{
return this.useCurrentUserProtectionScope;
}
}
public byte[] GetEntropy()
{
byte[] result = null;
if (this.entropy != null)
{
result = DiagnosticUtility.Utility.AllocateByteArray(this.entropy.Length);
Buffer.BlockCopy(this.entropy, 0, result, 0, this.entropy.Length);
}
return result;
}
public override string ToString()
{
StringBuilder result = new StringBuilder();
result.Append(this.GetType().ToString());
result.AppendFormat("{0} UseCurrentUserProtectionScope={1}", Environment.NewLine, this.useCurrentUserProtectionScope);
result.AppendFormat("{0} Entropy Length={1}", Environment.NewLine, (this.entropy == null) ? 0 : this.entropy.Length);
return result.ToString();
}
protected internal override byte[] DecodeSecurityState(byte[] data)
{
return ProtectedData.Unprotect(data, this.entropy, (this.useCurrentUserProtectionScope) ? DataProtectionScope.CurrentUser : DataProtectionScope.LocalMachine);
}
protected internal override byte[] EncodeSecurityState(byte[] data)
{
return ProtectedData.Protect(data, this.entropy, (this.useCurrentUserProtectionScope) ? DataProtectionScope.CurrentUser : DataProtectionScope.LocalMachine);
}
}
}
// 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
- SecurityDescriptor.cs
- Compiler.cs
- PolicyUnit.cs
- DataGridViewDataErrorEventArgs.cs
- DataGridCommandEventArgs.cs
- XmlSchemaRedefine.cs
- __Error.cs
- Token.cs
- DBBindings.cs
- DispatcherExceptionEventArgs.cs
- RuntimeConfigurationRecord.cs
- MenuItemCollectionEditorDialog.cs
- DataSetUtil.cs
- HttpsTransportElement.cs
- FolderBrowserDialogDesigner.cs
- LinkedResourceCollection.cs
- ScriptingJsonSerializationSection.cs
- StorageTypeMapping.cs
- HealthMonitoringSection.cs
- AttributeData.cs
- SerializationStore.cs
- StringInfo.cs
- RightsManagementErrorHandler.cs
- Identifier.cs
- JsonUriDataContract.cs
- RepeatInfo.cs
- Random.cs
- PasswordDeriveBytes.cs
- followingquery.cs
- LinearGradientBrush.cs
- DefaultPropertiesToSend.cs
- Int16AnimationUsingKeyFrames.cs
- NumberSubstitution.cs
- ExecutionEngineException.cs
- httpapplicationstate.cs
- ObjectDataSourceView.cs
- HttpGetServerProtocol.cs
- Identifier.cs
- Pts.cs
- Registry.cs
- UniqueIdentifierService.cs
- COM2ExtendedUITypeEditor.cs
- DataGridViewAdvancedBorderStyle.cs
- BlockingCollection.cs
- ApplicationException.cs
- BooleanFunctions.cs
- BitmapEncoder.cs
- EntityDataSourceDesignerHelper.cs
- CacheVirtualItemsEvent.cs
- XmlNode.cs
- WebPartAuthorizationEventArgs.cs
- GeneratedView.cs
- WindowInteropHelper.cs
- TextBoxLine.cs
- JsonFormatGeneratorStatics.cs
- TemplatePartAttribute.cs
- HasCopySemanticsAttribute.cs
- BindingCompleteEventArgs.cs
- ReadOnlyCollectionBase.cs
- PersonalizableTypeEntry.cs
- XmlDesigner.cs
- ProcessThread.cs
- DataKey.cs
- ManagementOperationWatcher.cs
- StartFileNameEditor.cs
- TextEditorParagraphs.cs
- _DigestClient.cs
- QuestionEventArgs.cs
- ImageField.cs
- CngAlgorithm.cs
- FactoryMaker.cs
- TableDetailsRow.cs
- HttpDebugHandler.cs
- ReadOnlyObservableCollection.cs
- LogicalTreeHelper.cs
- SaveFileDialog.cs
- InvalidCommandTreeException.cs
- WindowsScrollBarBits.cs
- CollectionChangeEventArgs.cs
- UxThemeWrapper.cs
- SchemaMapping.cs
- BuiltInExpr.cs
- PartialCachingAttribute.cs
- TraceSection.cs
- ResourceReader.cs
- InsufficientExecutionStackException.cs
- Int32Rect.cs
- ObjectHandle.cs
- TimelineGroup.cs
- SingleTagSectionHandler.cs
- SafeTimerHandle.cs
- UncommonField.cs
- EntryWrittenEventArgs.cs
- AdornedElementPlaceholder.cs
- ScriptResourceDefinition.cs
- SqlException.cs
- KeyedQueue.cs
- EntityDataSourceContextCreatingEventArgs.cs
- PageEventArgs.cs
- WinFormsSecurity.cs