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
- cookie.cs
- FileInfo.cs
- SqlBooleanMismatchVisitor.cs
- TablePatternIdentifiers.cs
- GenericIdentity.cs
- HttpListener.cs
- CustomAttribute.cs
- GridViewRowPresenter.cs
- HGlobalSafeHandle.cs
- HtmlEncodedRawTextWriter.cs
- XsltOutput.cs
- Enum.cs
- SystemParameters.cs
- ChildTable.cs
- StatusBar.cs
- LongPath.cs
- Paragraph.cs
- DataMemberListEditor.cs
- Memoizer.cs
- DynamicValueConverter.cs
- Themes.cs
- ellipse.cs
- VectorConverter.cs
- SchemaMapping.cs
- AppDomainShutdownMonitor.cs
- DataGridPageChangedEventArgs.cs
- SimpleTypeResolver.cs
- WorkflowServiceHostFactory.cs
- PersistencePipeline.cs
- PageTheme.cs
- ReadOnlyDictionary.cs
- DrawingGroup.cs
- SendMessageContent.cs
- DropDownList.cs
- HostingEnvironmentException.cs
- Deserializer.cs
- ListChangedEventArgs.cs
- Choices.cs
- GatewayDefinition.cs
- JulianCalendar.cs
- ListViewDesigner.cs
- StrokeIntersection.cs
- XmlNamedNodeMap.cs
- ApplicationServiceManager.cs
- NoneExcludedImageIndexConverter.cs
- PageCache.cs
- TextSelection.cs
- PageAsyncTask.cs
- Graphics.cs
- CodePageEncoding.cs
- TemplateBindingExtension.cs
- WrapPanel.cs
- GlobalItem.cs
- LockCookie.cs
- APCustomTypeDescriptor.cs
- AppSecurityManager.cs
- PlainXmlWriter.cs
- ModifyActivitiesPropertyDescriptor.cs
- TdsParserHelperClasses.cs
- DataSourceListEditor.cs
- WebConfigurationFileMap.cs
- ConnectionPoolRegistry.cs
- EdmItemError.cs
- LogExtentCollection.cs
- Parameter.cs
- CancellationState.cs
- AccessKeyManager.cs
- MarkupWriter.cs
- DataRowIndexBuffer.cs
- MetabaseServerConfig.cs
- TileBrush.cs
- FastEncoderWindow.cs
- Root.cs
- ExpandSegment.cs
- LayoutUtils.cs
- OleDbPermission.cs
- UnitySerializationHolder.cs
- SubMenuStyle.cs
- XPathMultyIterator.cs
- MessageEncoder.cs
- OracleParameterCollection.cs
- DescendantOverDescendantQuery.cs
- BufferBuilder.cs
- SecureUICommand.cs
- ResourceDescriptionAttribute.cs
- StateChangeEvent.cs
- StyleHelper.cs
- sqlser.cs
- GeneralTransform.cs
- SimpleLine.cs
- TargetInvocationException.cs
- HwndKeyboardInputProvider.cs
- TypeValidationEventArgs.cs
- MessageCredentialType.cs
- XmlExpressionDumper.cs
- OdbcReferenceCollection.cs
- SqlTransaction.cs
- NavigationExpr.cs
- WS2007FederationHttpBindingElement.cs
- TranslateTransform3D.cs