Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / Tokens / BinarySecretSecurityToken.cs / 1 / BinarySecretSecurityToken.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Security.Tokens
{
using System.Collections;
using System.ServiceModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Tokens;
using System.Security.Cryptography;
using System.Text;
using System.Xml;
public class BinarySecretSecurityToken : SecurityToken
{
string id;
DateTime effectiveTime;
byte[] key;
ReadOnlyCollection securityKeys;
public BinarySecretSecurityToken(int keySizeInBits)
: this(SecurityUniqueId.Create().Value, keySizeInBits)
{
}
public BinarySecretSecurityToken(string id, int keySizeInBits)
: this(id, keySizeInBits, true)
{
}
public BinarySecretSecurityToken(byte[] key)
: this(SecurityUniqueId.Create().Value, key)
{
}
public BinarySecretSecurityToken(string id, byte[] key)
: this(id, key, true)
{
}
protected BinarySecretSecurityToken(string id, int keySizeInBits, bool allowCrypto)
{
if (keySizeInBits <= 0 || keySizeInBits >= 512)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("keySizeInBits", SR.GetString(SR.ValueMustBeInRange, 0, 512)));
}
if ((keySizeInBits % 8) != 0)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("keySizeInBits", SR.GetString(SR.KeyLengthMustBeMultipleOfEight, keySizeInBits)));
}
this.id = id;
this.effectiveTime = DateTime.UtcNow;
this.key = new byte[keySizeInBits / 8];
CryptoHelper.FillRandomBytes(this.key);
if (allowCrypto)
{
this.securityKeys = SecurityUtils.CreateSymmetricSecurityKeys(this.key);
}
else
{
this.securityKeys = EmptyReadOnlyCollection.Instance;
}
}
protected BinarySecretSecurityToken(string id, byte[] key, bool allowCrypto)
{
if (key == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("key");
this.id = id;
this.effectiveTime = DateTime.UtcNow;
this.key = new byte[key.Length];
Buffer.BlockCopy(key, 0, this.key, 0, key.Length);
if (allowCrypto)
{
this.securityKeys = SecurityUtils.CreateSymmetricSecurityKeys(this.key);
}
else
{
this.securityKeys = EmptyReadOnlyCollection.Instance;
}
}
public override string Id
{
get { return this.id; }
}
public override DateTime ValidFrom
{
get { return this.effectiveTime; }
}
public override DateTime ValidTo
{
// Never expire
get { return DateTime.MaxValue; }
}
public int KeySize
{
get { return (this.key.Length * 8); }
}
public override ReadOnlyCollection SecurityKeys
{
get { return this.securityKeys; }
}
public byte[] GetKeyBytes()
{
return SecurityUtils.CloneBuffer(this.key);
}
}
}
// 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
- RegexReplacement.cs
- DashStyle.cs
- Keywords.cs
- RenderDataDrawingContext.cs
- DataListItemEventArgs.cs
- SchemaTableOptionalColumn.cs
- CookieParameter.cs
- RadioButton.cs
- CompoundFileReference.cs
- ListViewGroup.cs
- ChannelHandler.cs
- AppDomainAttributes.cs
- DriveInfo.cs
- SqlCacheDependencySection.cs
- ComboBoxAutomationPeer.cs
- BitStack.cs
- HtmlInputFile.cs
- ISAPIApplicationHost.cs
- SQLMembershipProvider.cs
- ToolStripContentPanel.cs
- SubstitutionList.cs
- ThreadAbortException.cs
- InstanceHandle.cs
- DesignerTransaction.cs
- PixelShader.cs
- ManipulationInertiaStartingEventArgs.cs
- DataControlFieldHeaderCell.cs
- ReaderWriterLock.cs
- TouchesOverProperty.cs
- DataRowView.cs
- DocumentCollection.cs
- PrintDialogException.cs
- HashHelpers.cs
- OracleBoolean.cs
- ConversionHelper.cs
- HostExecutionContextManager.cs
- AccessDataSource.cs
- XPathBinder.cs
- ViewLoader.cs
- TextEffectCollection.cs
- ToggleButtonAutomationPeer.cs
- XPathNavigatorKeyComparer.cs
- LookupNode.cs
- Serialization.cs
- FontWeightConverter.cs
- Rfc2898DeriveBytes.cs
- QueueProcessor.cs
- ToolboxCategoryItems.cs
- EmptyEnumerator.cs
- SafeHandles.cs
- Registry.cs
- SapiRecognizer.cs
- SchemaNamespaceManager.cs
- ObjectQuery.cs
- AdRotator.cs
- GeometryHitTestResult.cs
- DataControlImageButton.cs
- ToolStripControlHost.cs
- DataControlCommands.cs
- WebPartDisplayModeEventArgs.cs
- CodeLabeledStatement.cs
- VisualBasic.cs
- OdbcRowUpdatingEvent.cs
- SrgsElementList.cs
- FixUpCollection.cs
- DataServiceStreamProviderWrapper.cs
- MainMenu.cs
- CuspData.cs
- HandlerMappingMemo.cs
- SemaphoreSlim.cs
- AlgoModule.cs
- EncryptedKey.cs
- WebPartTransformer.cs
- ToolStripContainer.cs
- DataServiceContext.cs
- COM2EnumConverter.cs
- SharedDp.cs
- HGlobalSafeHandle.cs
- ImageBrush.cs
- ChangePasswordAutoFormat.cs
- SelectionBorderGlyph.cs
- HttpGetClientProtocol.cs
- SvcMapFileLoader.cs
- ThreadInterruptedException.cs
- ActivityInstanceReference.cs
- DocumentCollection.cs
- FormatStringEditor.cs
- SharedStatics.cs
- Permission.cs
- FileEnumerator.cs
- UseAttributeSetsAction.cs
- SynchronizedMessageSource.cs
- Boolean.cs
- EventEntry.cs
- TextFindEngine.cs
- Renderer.cs
- IncrementalReadDecoders.cs
- RouteValueDictionary.cs
- BaseInfoTable.cs
- UnitySerializationHolder.cs