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; ReadOnlyCollectionsecurityKeys; 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
- XsdBuilder.cs
- BitArray.cs
- GridViewDeleteEventArgs.cs
- FontFamilyConverter.cs
- DefaultSection.cs
- StructuredTypeEmitter.cs
- SqlClientFactory.cs
- SizeAnimationBase.cs
- JoinTreeNode.cs
- StringStorage.cs
- SettingsBindableAttribute.cs
- _SecureChannel.cs
- XsltLoader.cs
- GeneratedContractType.cs
- SecurityHelper.cs
- JavascriptCallbackBehaviorAttribute.cs
- StaticSiteMapProvider.cs
- ExpressionPrinter.cs
- SafePEFileHandle.cs
- ExceptionUtil.cs
- MethodAccessException.cs
- SortKey.cs
- LocationUpdates.cs
- PackagePartCollection.cs
- ImageField.cs
- ToolBarOverflowPanel.cs
- HotSpotCollection.cs
- WindowsPen.cs
- DeviceContext2.cs
- EventLogPermission.cs
- CatalogZoneBase.cs
- UndoEngine.cs
- FreeFormPanel.cs
- ToolboxItemCollection.cs
- StoreContentChangedEventArgs.cs
- HtmlControlAdapter.cs
- MailFileEditor.cs
- ToolStripGrip.cs
- MarkupExtensionParser.cs
- HostingEnvironmentSection.cs
- FormattedTextSymbols.cs
- ColorAnimationBase.cs
- RegionData.cs
- SettingsPropertyWrongTypeException.cs
- MutexSecurity.cs
- StylusButtonEventArgs.cs
- ListView.cs
- SelectionEditingBehavior.cs
- InstanceDataCollection.cs
- IssuedTokenParametersElement.cs
- documentsequencetextview.cs
- ToolStripTemplateNode.cs
- ParameterBuilder.cs
- FileUpload.cs
- WindowsGraphicsCacheManager.cs
- StylusDownEventArgs.cs
- StylusPointCollection.cs
- ChannelManager.cs
- ChangeTracker.cs
- ConnectionProviderAttribute.cs
- EntityCodeGenerator.cs
- CheckBoxField.cs
- ListSourceHelper.cs
- SizeChangedInfo.cs
- CodeBlockBuilder.cs
- MediaContext.cs
- View.cs
- DefaultObjectSerializer.cs
- Size.cs
- SendParametersContent.cs
- ShortcutKeysEditor.cs
- SmiContext.cs
- TreeBuilder.cs
- ContextStack.cs
- ListBase.cs
- XmlDesignerDataSourceView.cs
- LexicalChunk.cs
- DeploymentSection.cs
- MultipartIdentifier.cs
- Relationship.cs
- PngBitmapDecoder.cs
- Effect.cs
- ValidationHelper.cs
- XMLUtil.cs
- SqlDataSourceCommandParser.cs
- WindowsSysHeader.cs
- BinaryParser.cs
- FontStyles.cs
- Compiler.cs
- TypeDescriptionProviderAttribute.cs
- BoolLiteral.cs
- MemoryFailPoint.cs
- XmlSerializer.cs
- EventLogger.cs
- CssStyleCollection.cs
- SqlGenerator.cs
- DataTablePropertyDescriptor.cs
- Properties.cs
- ParallelEnumerableWrapper.cs
- ServiceModelConfigurationSectionCollection.cs