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
- ByteStreamMessageEncoder.cs
- cookie.cs
- ContentPresenter.cs
- TranslateTransform.cs
- CounterSetInstanceCounterDataSet.cs
- ArithmeticException.cs
- SocketPermission.cs
- StandardTransformFactory.cs
- webeventbuffer.cs
- InputLanguageCollection.cs
- TimeIntervalCollection.cs
- XPathEmptyIterator.cs
- SqlComparer.cs
- DrawListViewItemEventArgs.cs
- TextBox.cs
- RadioButton.cs
- CommonDialog.cs
- LassoSelectionBehavior.cs
- LockingPersistenceProvider.cs
- DriveInfo.cs
- DataSourceCache.cs
- DesignTimeTemplateParser.cs
- XpsException.cs
- NumberSubstitution.cs
- XamlFilter.cs
- UrlPath.cs
- OptimalBreakSession.cs
- WinFormsSpinner.cs
- EncoderNLS.cs
- _DisconnectOverlappedAsyncResult.cs
- Rotation3DAnimationBase.cs
- ConstraintCollection.cs
- RegexWorker.cs
- StorageComplexTypeMapping.cs
- TextChangedEventArgs.cs
- StyleXamlParser.cs
- XmlBindingWorker.cs
- SettingsBase.cs
- UriTemplateTableMatchCandidate.cs
- ForwardPositionQuery.cs
- SqlDataSourceEnumerator.cs
- XmlDataLoader.cs
- InheritanceContextChangedEventManager.cs
- WebZoneDesigner.cs
- X509CertificateCollection.cs
- IsolatedStorageFile.cs
- Mappings.cs
- sqlser.cs
- Int32CollectionConverter.cs
- TextFormatter.cs
- TrackBarRenderer.cs
- LocalizableAttribute.cs
- Keyboard.cs
- ConstraintEnumerator.cs
- AssemblyName.cs
- StrokeCollection2.cs
- PerformanceCounterPermissionAttribute.cs
- TraceEventCache.cs
- FontUnit.cs
- SafeNativeMethodsCLR.cs
- ClientClassGenerator.cs
- SwitchLevelAttribute.cs
- AtlasWeb.Designer.cs
- TextRunTypographyProperties.cs
- DefaultValueTypeConverter.cs
- PropertyEmitterBase.cs
- AsyncOperation.cs
- TdsRecordBufferSetter.cs
- CompositeActivityValidator.cs
- BidOverLoads.cs
- BamlResourceContent.cs
- _BasicClient.cs
- TextAnchor.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- TreeViewEvent.cs
- ComplusEndpointConfigContainer.cs
- PropertyGeneratedEventArgs.cs
- CompilerScope.Storage.cs
- BevelBitmapEffect.cs
- AssociationEndMember.cs
- UInt64Converter.cs
- AggregatePushdown.cs
- SettingsSavedEventArgs.cs
- ComponentResourceKeyConverter.cs
- HtmlMeta.cs
- CharStorage.cs
- BuildManager.cs
- XmlDataSource.cs
- SqlDataReader.cs
- SafeMemoryMappedFileHandle.cs
- InvalidOperationException.cs
- SqlUdtInfo.cs
- FileDialog.cs
- DbCommandTree.cs
- SelectionUIService.cs
- Model3D.cs
- DocumentOrderQuery.cs
- TableRow.cs
- ProfilePropertyMetadata.cs
- XmlUrlEditor.cs