Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SymmetricKey.cs / 1305376 / SymmetricKey.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System.IdentityModel.Selectors; using System.Security.Cryptography; public class InMemorySymmetricSecurityKey : SymmetricSecurityKey { int keySize; byte[] symmetricKey; public InMemorySymmetricSecurityKey(byte[] symmetricKey) : this(symmetricKey, true) { } public InMemorySymmetricSecurityKey(byte[] symmetricKey, bool cloneBuffer) { if (symmetricKey == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("symmetricKey")); } if (symmetricKey.Length == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SymmetricKeyLengthTooShort, symmetricKey.Length))); } this.keySize = symmetricKey.Length * 8; if (cloneBuffer) { this.symmetricKey = new byte[symmetricKey.Length]; Buffer.BlockCopy(symmetricKey, 0, this.symmetricKey, 0, symmetricKey.Length); } else { this.symmetricKey = symmetricKey; } } public override int KeySize { get { return this.keySize; } } public override byte[] DecryptKey(string algorithm, byte[] keyData) { return CryptoHelper.UnwrapKey(this.symmetricKey, keyData, algorithm); } public override byte[] EncryptKey(string algorithm, byte[] keyData) { return CryptoHelper.WrapKey(this.symmetricKey, keyData, algorithm); } public override byte[] GenerateDerivedKey(string algorithm, byte[] label, byte[] nonce, int derivedKeyLength, int offset) { return CryptoHelper.GenerateDerivedKey(this.symmetricKey, algorithm, label, nonce, derivedKeyLength, offset); } public override ICryptoTransform GetDecryptionTransform(string algorithm, byte[] iv) { return CryptoHelper.CreateDecryptor(this.symmetricKey, iv, algorithm); } public override ICryptoTransform GetEncryptionTransform(string algorithm, byte[] iv) { return CryptoHelper.CreateEncryptor(this.symmetricKey, iv, algorithm); } public override int GetIVSize(string algorithm) { return CryptoHelper.GetIVSize(algorithm); } public override KeyedHashAlgorithm GetKeyedHashAlgorithm(string algorithm) { return CryptoHelper.CreateKeyedHashAlgorithm(this.symmetricKey, algorithm); } public override SymmetricAlgorithm GetSymmetricAlgorithm(string algorithm) { return CryptoHelper.GetSymmetricAlgorithm(this.symmetricKey, algorithm); } public override byte[] GetSymmetricKey() { byte[] local = new byte[this.symmetricKey.Length]; Buffer.BlockCopy(this.symmetricKey, 0, local, 0, this.symmetricKey.Length); return local; } public override bool IsAsymmetricAlgorithm(string algorithm) { return (CryptoHelper.IsAsymmetricAlgorithm(algorithm)); } public override bool IsSupportedAlgorithm(string algorithm) { return (CryptoHelper.IsSymmetricSupportedAlgorithm(algorithm, this.KeySize)); } public override bool IsSymmetricAlgorithm(string algorithm) { return CryptoHelper.IsSymmetricAlgorithm(algorithm); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System.IdentityModel.Selectors; using System.Security.Cryptography; public class InMemorySymmetricSecurityKey : SymmetricSecurityKey { int keySize; byte[] symmetricKey; public InMemorySymmetricSecurityKey(byte[] symmetricKey) : this(symmetricKey, true) { } public InMemorySymmetricSecurityKey(byte[] symmetricKey, bool cloneBuffer) { if (symmetricKey == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("symmetricKey")); } if (symmetricKey.Length == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.SymmetricKeyLengthTooShort, symmetricKey.Length))); } this.keySize = symmetricKey.Length * 8; if (cloneBuffer) { this.symmetricKey = new byte[symmetricKey.Length]; Buffer.BlockCopy(symmetricKey, 0, this.symmetricKey, 0, symmetricKey.Length); } else { this.symmetricKey = symmetricKey; } } public override int KeySize { get { return this.keySize; } } public override byte[] DecryptKey(string algorithm, byte[] keyData) { return CryptoHelper.UnwrapKey(this.symmetricKey, keyData, algorithm); } public override byte[] EncryptKey(string algorithm, byte[] keyData) { return CryptoHelper.WrapKey(this.symmetricKey, keyData, algorithm); } public override byte[] GenerateDerivedKey(string algorithm, byte[] label, byte[] nonce, int derivedKeyLength, int offset) { return CryptoHelper.GenerateDerivedKey(this.symmetricKey, algorithm, label, nonce, derivedKeyLength, offset); } public override ICryptoTransform GetDecryptionTransform(string algorithm, byte[] iv) { return CryptoHelper.CreateDecryptor(this.symmetricKey, iv, algorithm); } public override ICryptoTransform GetEncryptionTransform(string algorithm, byte[] iv) { return CryptoHelper.CreateEncryptor(this.symmetricKey, iv, algorithm); } public override int GetIVSize(string algorithm) { return CryptoHelper.GetIVSize(algorithm); } public override KeyedHashAlgorithm GetKeyedHashAlgorithm(string algorithm) { return CryptoHelper.CreateKeyedHashAlgorithm(this.symmetricKey, algorithm); } public override SymmetricAlgorithm GetSymmetricAlgorithm(string algorithm) { return CryptoHelper.GetSymmetricAlgorithm(this.symmetricKey, algorithm); } public override byte[] GetSymmetricKey() { byte[] local = new byte[this.symmetricKey.Length]; Buffer.BlockCopy(this.symmetricKey, 0, local, 0, this.symmetricKey.Length); return local; } public override bool IsAsymmetricAlgorithm(string algorithm) { return (CryptoHelper.IsAsymmetricAlgorithm(algorithm)); } public override bool IsSupportedAlgorithm(string algorithm) { return (CryptoHelper.IsSymmetricSupportedAlgorithm(algorithm, this.KeySize)); } public override bool IsSymmetricAlgorithm(string algorithm) { return CryptoHelper.IsSymmetricAlgorithm(algorithm); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StylusPointPropertyInfo.cs
- WindowsFont.cs
- ListViewTableRow.cs
- XpsDocument.cs
- DependentTransaction.cs
- UshortList2.cs
- GridViewAutomationPeer.cs
- Roles.cs
- LineBreakRecord.cs
- DataGridRowsPresenter.cs
- XmlSchemaException.cs
- CheckedPointers.cs
- InstanceOwner.cs
- GeneralTransform3DGroup.cs
- PropertyItem.cs
- TreeViewItemAutomationPeer.cs
- XmlWriter.cs
- CallbackBehaviorAttribute.cs
- SynchronizedMessageSource.cs
- SymLanguageType.cs
- OneOfConst.cs
- FormatSettings.cs
- MenuBindingsEditorForm.cs
- XpsThumbnail.cs
- XslCompiledTransform.cs
- SqlCommand.cs
- DataColumnCollection.cs
- Crypto.cs
- ToolStripOverflowButton.cs
- XPathEmptyIterator.cs
- DataObjectEventArgs.cs
- WebPartExportVerb.cs
- WindowsTreeView.cs
- ProviderSettings.cs
- UnitySerializationHolder.cs
- ResourceReader.cs
- uribuilder.cs
- TemplatedAdorner.cs
- SHA1Managed.cs
- GlyphCollection.cs
- DeferredTextReference.cs
- FormatConvertedBitmap.cs
- TabControlCancelEvent.cs
- Menu.cs
- GroupQuery.cs
- ZoneLinkButton.cs
- QilStrConcatenator.cs
- RoutedEventConverter.cs
- keycontainerpermission.cs
- XsdDuration.cs
- TextModifier.cs
- CodeAssignStatement.cs
- ProtocolsConfigurationHandler.cs
- SystemTcpStatistics.cs
- X509ChainElement.cs
- FormViewModeEventArgs.cs
- Parameter.cs
- ErrorHandlingReceiver.cs
- Queue.cs
- CompoundFileStorageReference.cs
- InternalControlCollection.cs
- XmlSchema.cs
- TimeManager.cs
- FileInfo.cs
- _UriTypeConverter.cs
- VersionValidator.cs
- SystemGatewayIPAddressInformation.cs
- DesignerHost.cs
- _ChunkParse.cs
- DeflateEmulationStream.cs
- DockingAttribute.cs
- UInt64Storage.cs
- QilTypeChecker.cs
- FileDialogCustomPlace.cs
- DecimalSumAggregationOperator.cs
- ZipIOFileItemStream.cs
- Rotation3DAnimationUsingKeyFrames.cs
- HyperLinkColumn.cs
- OrthographicCamera.cs
- DataBoundLiteralControl.cs
- Solver.cs
- HandlerElementCollection.cs
- Vertex.cs
- TextPenaltyModule.cs
- CodeSnippetStatement.cs
- SafeMemoryMappedViewHandle.cs
- ToolBarButtonClickEvent.cs
- LinkedDataMemberFieldEditor.cs
- AnimatedTypeHelpers.cs
- RegexWorker.cs
- EncryptedReference.cs
- EntityContainerRelationshipSet.cs
- ConfigXmlDocument.cs
- LayoutEvent.cs
- TextBoxAutoCompleteSourceConverter.cs
- SecurityPermission.cs
- keycontainerpermission.cs
- InstanceNormalEvent.cs
- ProfileSection.cs
- MouseGestureConverter.cs