Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / SymmetricKey.cs / 1 / 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.IsSymmetricAlgorithm(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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- loginstatus.cs
- EnumUnknown.cs
- OpenTypeLayout.cs
- FontWeightConverter.cs
- SecurityCriticalDataForSet.cs
- UnauthorizedWebPart.cs
- ProjectionPathBuilder.cs
- TypeConverterHelper.cs
- OperandQuery.cs
- SectionVisual.cs
- TriggerBase.cs
- SecureStringHasher.cs
- ControlIdConverter.cs
- ClientSettingsProvider.cs
- WebPartCancelEventArgs.cs
- PathFigureCollectionConverter.cs
- StatusBarPanel.cs
- ServiceDeploymentInfo.cs
- RadioButtonBaseAdapter.cs
- DataExchangeServiceBinder.cs
- BrushValueSerializer.cs
- VarRemapper.cs
- HMACMD5.cs
- SweepDirectionValidation.cs
- GridViewHeaderRowPresenterAutomationPeer.cs
- PenContexts.cs
- InvalidAsynchronousStateException.cs
- Light.cs
- BinaryFormatterWriter.cs
- CurrentTimeZone.cs
- OutputCacheProfile.cs
- Bitmap.cs
- TextEditorSpelling.cs
- FunctionDetailsReader.cs
- InputScopeNameConverter.cs
- RouteParser.cs
- EditingCommands.cs
- RawStylusSystemGestureInputReport.cs
- Timer.cs
- KeyValueSerializer.cs
- FtpWebResponse.cs
- JsonReader.cs
- CompensationParticipant.cs
- InvalidateEvent.cs
- IdentityManager.cs
- ObjectStorage.cs
- SafeViewOfFileHandle.cs
- StreamUpgradeProvider.cs
- Condition.cs
- CustomValidator.cs
- ping.cs
- PersistenceProviderElement.cs
- ProviderConnectionPointCollection.cs
- DataObjectSettingDataEventArgs.cs
- MiniMapControl.xaml.cs
- DomainLiteralReader.cs
- EntityContainerEntitySetDefiningQuery.cs
- DropSourceBehavior.cs
- TreeIterators.cs
- InputEventArgs.cs
- SafeThemeHandle.cs
- OrderedDictionaryStateHelper.cs
- EntityConnectionStringBuilderItem.cs
- LingerOption.cs
- WindowCollection.cs
- Command.cs
- TargetParameterCountException.cs
- OLEDB_Enum.cs
- M3DUtil.cs
- FormCollection.cs
- TypeContext.cs
- Mouse.cs
- DataGridItem.cs
- DisposableCollectionWrapper.cs
- DBConcurrencyException.cs
- PageContent.cs
- FastEncoder.cs
- SqlClientWrapperSmiStreamChars.cs
- FontSizeConverter.cs
- HttpApplicationStateWrapper.cs
- SaveFileDialogDesigner.cs
- Debugger.cs
- _ShellExpression.cs
- XmlFormatReaderGenerator.cs
- WinFormsComponentEditor.cs
- UIServiceHelper.cs
- CodeDOMProvider.cs
- EventSinkHelperWriter.cs
- PresentationAppDomainManager.cs
- StringToken.cs
- RtType.cs
- UnionExpr.cs
- ItemCollection.cs
- SoapFault.cs
- DesignerDataTable.cs
- PackageDigitalSignature.cs
- FileUtil.cs
- PropertyPathWorker.cs
- StartUpEventArgs.cs
- NavigationExpr.cs