Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / clr / src / BCL / System / Reflection / StrongNameKeyPair.cs / 1 / StrongNameKeyPair.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** File: StrongNameKeyPair.cs ** ** ** Purpose: Encapsulate access to a public/private key pair ** used to sign strong name assemblies. ** ** ===========================================================*/ namespace System.Reflection { using System; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Security.Permissions; [Serializable()] [System.Runtime.InteropServices.ComVisible(true)] public class StrongNameKeyPair : IDeserializationCallback, ISerializable { private bool _keyPairExported; private byte[] _keyPairArray; private String _keyPairContainer; private byte[] _publicKey; // Build key pair from file. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(FileStream keyPairFile) { if (keyPairFile == null) throw new ArgumentNullException("keyPairFile"); int length = (int)keyPairFile.Length; _keyPairArray = new byte[length]; keyPairFile.Read(_keyPairArray, 0, length); _keyPairExported = true; } // Build key pair from byte array in memory. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(byte[] keyPairArray) { if (keyPairArray == null) throw new ArgumentNullException("keyPairArray"); _keyPairArray = new byte[keyPairArray.Length]; Array.Copy(keyPairArray, _keyPairArray, keyPairArray.Length); _keyPairExported = true; } // Reference key pair in named key container. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(String keyPairContainer) { if (keyPairContainer == null) throw new ArgumentNullException("keyPairContainer"); _keyPairContainer = keyPairContainer; _keyPairExported = false; } [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] protected StrongNameKeyPair (SerializationInfo info, StreamingContext context) { _keyPairExported = (bool) info.GetValue("_keyPairExported", typeof(bool)); _keyPairArray = (byte[]) info.GetValue("_keyPairArray", typeof(byte[])); _keyPairContainer = (string) info.GetValue("_keyPairContainer", typeof(string)); _publicKey = (byte[]) info.GetValue("_publicKey", typeof(byte[])); } // Get the public portion of the key pair. public byte[] PublicKey { get { if (_publicKey == null) { _publicKey = nGetPublicKey(_keyPairExported, _keyPairArray, _keyPairContainer); } byte[] publicKey = new byte[_publicKey.Length]; Array.Copy(_publicKey, publicKey, _publicKey.Length); return publicKey; } } ///void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) { info.AddValue("_keyPairExported", _keyPairExported); info.AddValue("_keyPairArray", _keyPairArray); info.AddValue("_keyPairContainer", _keyPairContainer); info.AddValue("_publicKey", _publicKey); } /// void IDeserializationCallback.OnDeserialization (Object sender) {} // Internal routine used to retrieve key pair info from unmanaged code. private bool GetKeyPair(out Object arrayOrContainer) { arrayOrContainer = _keyPairExported ? (Object)_keyPairArray : (Object)_keyPairContainer; return _keyPairExported; } [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern byte[] nGetPublicKey(bool exported, byte[] array, String container); } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** File: StrongNameKeyPair.cs ** ** ** Purpose: Encapsulate access to a public/private key pair ** used to sign strong name assemblies. ** ** ===========================================================*/ namespace System.Reflection { using System; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Security.Permissions; [Serializable()] [System.Runtime.InteropServices.ComVisible(true)] public class StrongNameKeyPair : IDeserializationCallback, ISerializable { private bool _keyPairExported; private byte[] _keyPairArray; private String _keyPairContainer; private byte[] _publicKey; // Build key pair from file. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(FileStream keyPairFile) { if (keyPairFile == null) throw new ArgumentNullException("keyPairFile"); int length = (int)keyPairFile.Length; _keyPairArray = new byte[length]; keyPairFile.Read(_keyPairArray, 0, length); _keyPairExported = true; } // Build key pair from byte array in memory. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(byte[] keyPairArray) { if (keyPairArray == null) throw new ArgumentNullException("keyPairArray"); _keyPairArray = new byte[keyPairArray.Length]; Array.Copy(keyPairArray, _keyPairArray, keyPairArray.Length); _keyPairExported = true; } // Reference key pair in named key container. [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] public StrongNameKeyPair(String keyPairContainer) { if (keyPairContainer == null) throw new ArgumentNullException("keyPairContainer"); _keyPairContainer = keyPairContainer; _keyPairExported = false; } [SecurityPermissionAttribute(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)] protected StrongNameKeyPair (SerializationInfo info, StreamingContext context) { _keyPairExported = (bool) info.GetValue("_keyPairExported", typeof(bool)); _keyPairArray = (byte[]) info.GetValue("_keyPairArray", typeof(byte[])); _keyPairContainer = (string) info.GetValue("_keyPairContainer", typeof(string)); _publicKey = (byte[]) info.GetValue("_publicKey", typeof(byte[])); } // Get the public portion of the key pair. public byte[] PublicKey { get { if (_publicKey == null) { _publicKey = nGetPublicKey(_keyPairExported, _keyPairArray, _keyPairContainer); } byte[] publicKey = new byte[_publicKey.Length]; Array.Copy(_publicKey, publicKey, _publicKey.Length); return publicKey; } } /// void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context) { info.AddValue("_keyPairExported", _keyPairExported); info.AddValue("_keyPairArray", _keyPairArray); info.AddValue("_keyPairContainer", _keyPairContainer); info.AddValue("_publicKey", _publicKey); } /// void IDeserializationCallback.OnDeserialization (Object sender) {} // Internal routine used to retrieve key pair info from unmanaged code. private bool GetKeyPair(out Object arrayOrContainer) { arrayOrContainer = _keyPairExported ? (Object)_keyPairArray : (Object)_keyPairContainer; return _keyPairExported; } [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern byte[] nGetPublicKey(bool exported, byte[] array, String container); } } // 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
- CryptographicAttribute.cs
- DataGridViewCellLinkedList.cs
- XmlSchemaSequence.cs
- DependencyPropertyValueSerializer.cs
- EnvironmentPermission.cs
- SQLDateTime.cs
- CmsInterop.cs
- LicenseContext.cs
- ApplicationContext.cs
- SynchronizationContext.cs
- MSG.cs
- MetabaseSettings.cs
- XPathDescendantIterator.cs
- ApplicationFileParser.cs
- XmlSchemaAll.cs
- FileFormatException.cs
- DataRowExtensions.cs
- BinaryQueryOperator.cs
- CompilationLock.cs
- AsymmetricCryptoHandle.cs
- MemberInfoSerializationHolder.cs
- CompositeFontParser.cs
- ControllableStoryboardAction.cs
- ValidationHelper.cs
- DataContractSerializerSection.cs
- IdSpace.cs
- TreeChangeInfo.cs
- InfoCardListRequest.cs
- CodeObjectCreateExpression.cs
- PageRouteHandler.cs
- RichTextBox.cs
- DoubleAnimation.cs
- UnwrappedTypesXmlSerializerManager.cs
- IsolatedStorageFile.cs
- ViewStateModeByIdAttribute.cs
- FieldNameLookup.cs
- UnitySerializationHolder.cs
- MediaCommands.cs
- Base64Encoder.cs
- MD5.cs
- SerializationInfoEnumerator.cs
- WebPartHelpVerb.cs
- AsnEncodedData.cs
- XPathEmptyIterator.cs
- ScriptingRoleServiceSection.cs
- SimpleApplicationHost.cs
- FormViewCommandEventArgs.cs
- ContentType.cs
- ColumnTypeConverter.cs
- WorkflowInstance.cs
- RepeaterItem.cs
- EUCJPEncoding.cs
- HwndStylusInputProvider.cs
- Point.cs
- ClientApiGenerator.cs
- CharStorage.cs
- DoubleLinkListEnumerator.cs
- MobileSysDescriptionAttribute.cs
- OletxDependentTransaction.cs
- XPathNavigatorReader.cs
- AvTrace.cs
- TemplateBindingExtensionConverter.cs
- ImageFormatConverter.cs
- InputLanguageCollection.cs
- PriorityQueue.cs
- PageParser.cs
- BinHexEncoding.cs
- QueryPageSettingsEventArgs.cs
- login.cs
- ColorTransform.cs
- CodeConstructor.cs
- X509UI.cs
- AnimationTimeline.cs
- SystemException.cs
- XmlLanguage.cs
- InvalidOleVariantTypeException.cs
- GridViewSortEventArgs.cs
- GridViewCommandEventArgs.cs
- EncodingInfo.cs
- SerializationException.cs
- OracleBoolean.cs
- OdbcFactory.cs
- DynamicDiscoveryDocument.cs
- Maps.cs
- JoinElimination.cs
- DbTransaction.cs
- DataContractJsonSerializerOperationBehavior.cs
- ObjectDataSourceMethodEventArgs.cs
- BamlVersionHeader.cs
- MailDefinition.cs
- EntityDataSourceChangingEventArgs.cs
- ChooseAction.cs
- OdbcConnectionHandle.cs
- FormViewDeletedEventArgs.cs
- XPathDocumentIterator.cs
- BufferedMessageData.cs
- SingleTagSectionHandler.cs
- PagePropertiesChangingEventArgs.cs
- URIFormatException.cs
- HttpBufferlessInputStream.cs