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
- M3DUtil.cs
- StopStoryboard.cs
- StrokeCollection2.cs
- CookieProtection.cs
- XNodeNavigator.cs
- ServiceDescriptionReflector.cs
- ComplexTypeEmitter.cs
- DbParameterCollection.cs
- TdsParserStaticMethods.cs
- ClientBuildManager.cs
- AdapterUtil.cs
- followingsibling.cs
- SendKeys.cs
- AVElementHelper.cs
- ComplexType.cs
- DelegatingMessage.cs
- SecurityDocument.cs
- CategoryEditor.cs
- StaticExtensionConverter.cs
- IdentityReference.cs
- TreeNodeStyleCollection.cs
- InfoCardSymmetricAlgorithm.cs
- AsyncPostBackTrigger.cs
- FamilyTypeface.cs
- querybuilder.cs
- precedingquery.cs
- BitmapCodecInfoInternal.cs
- EntitySqlQueryCacheKey.cs
- XamlReaderHelper.cs
- ColumnResizeUndoUnit.cs
- SurrogateDataContract.cs
- EntitySqlException.cs
- DbCommandDefinition.cs
- PointAnimationUsingKeyFrames.cs
- CalloutQueueItem.cs
- Property.cs
- TextTrailingWordEllipsis.cs
- AdornerLayer.cs
- BindingsCollection.cs
- RayMeshGeometry3DHitTestResult.cs
- XmlCDATASection.cs
- SmtpNegotiateAuthenticationModule.cs
- EDesignUtil.cs
- __Filters.cs
- TimersDescriptionAttribute.cs
- ParameterModifier.cs
- HiddenField.cs
- CriticalFinalizerObject.cs
- IsolatedStorageSecurityState.cs
- WebResourceUtil.cs
- ListSourceHelper.cs
- BaseDataBoundControl.cs
- ToolZoneDesigner.cs
- GreenMethods.cs
- ImmutableAssemblyCacheEntry.cs
- ReadOnlyObservableCollection.cs
- ProvideValueServiceProvider.cs
- __FastResourceComparer.cs
- XmlTextReader.cs
- ConfigurationSectionGroup.cs
- SingleStorage.cs
- DefaultEventAttribute.cs
- IdentityModelStringsVersion1.cs
- CompilerState.cs
- ReadingWritingEntityEventArgs.cs
- Pair.cs
- SystemSounds.cs
- SiteMapPath.cs
- Int32AnimationUsingKeyFrames.cs
- StrongNamePublicKeyBlob.cs
- TextProperties.cs
- XamlPathDataSerializer.cs
- SystemParameters.cs
- UrlPropertyAttribute.cs
- DataGridViewCellStyleBuilderDialog.cs
- DebugTrace.cs
- DataGridViewCellPaintingEventArgs.cs
- LayoutTable.cs
- FaultHandlingFilter.cs
- SplitterCancelEvent.cs
- CapabilitiesSection.cs
- SQLStringStorage.cs
- QueryPageSettingsEventArgs.cs
- IntellisenseTextBox.designer.cs
- TriggerActionCollection.cs
- TransformConverter.cs
- CollectionViewSource.cs
- GenerateDerivedKeyRequest.cs
- Rule.cs
- FormCollection.cs
- EntityViewContainer.cs
- SubpageParaClient.cs
- BinaryUtilClasses.cs
- TracingConnectionListener.cs
- MaskInputRejectedEventArgs.cs
- DataGridViewSortCompareEventArgs.cs
- CalendarDateRangeChangingEventArgs.cs
- LinqDataSourceEditData.cs
- DataGridViewCellStyle.cs
- CompositeControl.cs