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
- CreateInstanceBinder.cs
- GradientStop.cs
- SamlEvidence.cs
- BaseParaClient.cs
- SoapConverter.cs
- SafeRightsManagementEnvironmentHandle.cs
- TogglePatternIdentifiers.cs
- PatternMatcher.cs
- DesignTimeType.cs
- DataGridViewSelectedColumnCollection.cs
- CodePropertyReferenceExpression.cs
- PerformanceCounterPermission.cs
- Mouse.cs
- MenuStrip.cs
- PackageDigitalSignature.cs
- ImmutableObjectAttribute.cs
- ClonableStack.cs
- SaveFileDialog.cs
- ThreadInterruptedException.cs
- StrongTypingException.cs
- StylusPointPropertyId.cs
- EdmProperty.cs
- GeneralTransformCollection.cs
- BooleanStorage.cs
- ServiceBehaviorAttribute.cs
- Unit.cs
- Point4D.cs
- MemberRelationshipService.cs
- HttpListenerPrefixCollection.cs
- EmptyReadOnlyDictionaryInternal.cs
- PrinterUnitConvert.cs
- SupportsEventValidationAttribute.cs
- XmlDownloadManager.cs
- LookupNode.cs
- ValidatingReaderNodeData.cs
- ToolStripDropDownClosingEventArgs.cs
- TableCellAutomationPeer.cs
- ColumnCollection.cs
- TextRangeEditTables.cs
- RectangleHotSpot.cs
- NativeMethods.cs
- ListMarkerSourceInfo.cs
- PathData.cs
- SimpleRecyclingCache.cs
- EventLogPermission.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- OleAutBinder.cs
- DependsOnAttribute.cs
- WebPartZoneBase.cs
- VectorValueSerializer.cs
- PassportPrincipal.cs
- FileStream.cs
- TypeHelpers.cs
- Transform.cs
- RawTextInputReport.cs
- OutputScopeManager.cs
- SiteMapNodeItem.cs
- ClickablePoint.cs
- SingleResultAttribute.cs
- versioninfo.cs
- QilInvokeLateBound.cs
- COM2IDispatchConverter.cs
- PixelShader.cs
- AnnotationMap.cs
- FontWeight.cs
- ObjectStorage.cs
- HashMembershipCondition.cs
- FlowLayout.cs
- RegularExpressionValidator.cs
- UIntPtr.cs
- DbProviderFactory.cs
- StylusCaptureWithinProperty.cs
- String.cs
- CompositeCollection.cs
- UpdateTracker.cs
- SqlCacheDependencyDatabaseCollection.cs
- RegisterInfo.cs
- HighlightVisual.cs
- SqlServices.cs
- XmlValidatingReaderImpl.cs
- ListViewInsertionMark.cs
- ComPlusThreadInitializer.cs
- TemplatedAdorner.cs
- HttpRequest.cs
- NonSerializedAttribute.cs
- SessionEndingCancelEventArgs.cs
- QuotedPrintableStream.cs
- ListDictionary.cs
- InternalTransaction.cs
- RoleGroup.cs
- DeferredSelectedIndexReference.cs
- parserscommon.cs
- DescriptionAttribute.cs
- LOSFormatter.cs
- Rotation3DAnimationBase.cs
- AutoGeneratedField.cs
- NotificationContext.cs
- DataServices.cs
- MemberMaps.cs
- ProviderSettings.cs