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
- RetrieveVirtualItemEventArgs.cs
- InstalledFontCollection.cs
- Compress.cs
- TemplateBuilder.cs
- SqlCommandSet.cs
- DataPointer.cs
- XmlTextWriter.cs
- MetricEntry.cs
- CodeLabeledStatement.cs
- ReversePositionQuery.cs
- Visual3D.cs
- Size.cs
- CatalogPart.cs
- ScriptReference.cs
- Polygon.cs
- PropertyValueUIItem.cs
- TypeDescriptionProviderAttribute.cs
- Decimal.cs
- BreakRecordTable.cs
- TypedTableGenerator.cs
- SafeFreeMibTable.cs
- SystemResources.cs
- ObjectQuery_EntitySqlExtensions.cs
- PageClientProxyGenerator.cs
- DataGridAutoGeneratingColumnEventArgs.cs
- HandlerBase.cs
- KnownColorTable.cs
- TagPrefixCollection.cs
- KeyboardNavigation.cs
- EventDescriptorCollection.cs
- EventLogPermissionEntryCollection.cs
- TraceSection.cs
- DataTableReader.cs
- SecurityTokenProviderContainer.cs
- SafeWaitHandle.cs
- ScanQueryOperator.cs
- PowerStatus.cs
- ConfigXmlCDataSection.cs
- SQlBooleanStorage.cs
- UIElementIsland.cs
- Int16AnimationBase.cs
- UserNameSecurityTokenProvider.cs
- DependencyObjectType.cs
- WindowsSolidBrush.cs
- PriorityChain.cs
- VirtualizedItemProviderWrapper.cs
- SqlNamer.cs
- FontConverter.cs
- QilParameter.cs
- AppDomainAttributes.cs
- ToolStripCollectionEditor.cs
- MediaTimeline.cs
- handlecollector.cs
- NumericUpDownAcceleration.cs
- PreservationFileReader.cs
- FirewallWrapper.cs
- FlowLayoutPanelDesigner.cs
- HostnameComparisonMode.cs
- UriScheme.cs
- ListParagraph.cs
- RoleGroup.cs
- BasicViewGenerator.cs
- SqlWebEventProvider.cs
- securitycriticaldataformultiplegetandset.cs
- VectorCollectionConverter.cs
- SqlVersion.cs
- FontDifferentiator.cs
- ButtonBase.cs
- CodeConstructor.cs
- DataSetFieldSchema.cs
- PropertyEmitter.cs
- RealizationContext.cs
- CheckBox.cs
- Literal.cs
- BinaryMethodMessage.cs
- Component.cs
- NotConverter.cs
- Vector3DIndependentAnimationStorage.cs
- CompilerCollection.cs
- SimpleRecyclingCache.cs
- COM2PictureConverter.cs
- JsonEncodingStreamWrapper.cs
- ProviderBase.cs
- ProcessModelInfo.cs
- InputScopeConverter.cs
- ControlEvent.cs
- DelegatingConfigHost.cs
- SimpleFieldTemplateUserControl.cs
- InputProviderSite.cs
- EntityDataSourceColumn.cs
- JpegBitmapEncoder.cs
- SqlDataSourceEnumerator.cs
- BidOverLoads.cs
- PackWebRequestFactory.cs
- XhtmlConformanceSection.cs
- safePerfProviderHandle.cs
- StringDictionaryWithComparer.cs
- PolyBezierSegmentFigureLogic.cs
- Simplifier.cs
- InnerItemCollectionView.cs