Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / 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); } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RequestCacheManager.cs
- ObjRef.cs
- DesignerDataRelationship.cs
- XmlReturnWriter.cs
- EnumMember.cs
- LinearGradientBrush.cs
- DATA_BLOB.cs
- HMACMD5.cs
- coordinatorscratchpad.cs
- TypeExtension.cs
- FlowLayoutSettings.cs
- XmlIlGenerator.cs
- MobileFormsAuthentication.cs
- NavigationPropertySingletonExpression.cs
- ResourceManagerWrapper.cs
- TreeView.cs
- WmiInstallComponent.cs
- HostedBindingBehavior.cs
- FontStretchConverter.cs
- ColorTransform.cs
- WebUtil.cs
- QEncodedStream.cs
- AudienceUriMode.cs
- RoleManagerModule.cs
- ADRoleFactory.cs
- SubordinateTransaction.cs
- TraceRecord.cs
- RegistryPermission.cs
- ComponentRenameEvent.cs
- ClientData.cs
- MetadataUtil.cs
- ProcessManager.cs
- FreezableDefaultValueFactory.cs
- PermissionRequestEvidence.cs
- WorkflowDispatchContext.cs
- WsdlHelpGeneratorElement.cs
- InvalidEnumArgumentException.cs
- GridViewCommandEventArgs.cs
- Image.cs
- ValidatorCompatibilityHelper.cs
- ProfileGroupSettingsCollection.cs
- ProcessHost.cs
- URI.cs
- DockProviderWrapper.cs
- ApplicationFileParser.cs
- CompositeScriptReference.cs
- FixedTextSelectionProcessor.cs
- AnimationException.cs
- XmlSerializationGeneratedCode.cs
- WSFederationHttpSecurityElement.cs
- PenContexts.cs
- ListViewCancelEventArgs.cs
- SourceFileBuildProvider.cs
- SymLanguageType.cs
- CalendarButtonAutomationPeer.cs
- WebPartCancelEventArgs.cs
- SpeakInfo.cs
- ParagraphResult.cs
- BitHelper.cs
- FormViewModeEventArgs.cs
- Vector3DAnimationUsingKeyFrames.cs
- AppDomainInfo.cs
- HtmlSelect.cs
- Size.cs
- SubclassTypeValidator.cs
- CTreeGenerator.cs
- PasswordTextContainer.cs
- LinqDataSource.cs
- SectionUpdates.cs
- sqlser.cs
- VSWCFServiceContractGenerator.cs
- ToRequest.cs
- TableItemPattern.cs
- SecurityPolicySection.cs
- RepeatButtonAutomationPeer.cs
- EnumerableValidator.cs
- LinkedList.cs
- DbProviderManifest.cs
- Pkcs7Signer.cs
- SqlFunctionAttribute.cs
- PlatformNotSupportedException.cs
- MultipleViewProviderWrapper.cs
- DetailsViewDeletedEventArgs.cs
- WebDescriptionAttribute.cs
- TagMapCollection.cs
- DefinitionUpdate.cs
- IListConverters.cs
- ContractMapping.cs
- GetWorkflowTree.cs
- Bookmark.cs
- DescendentsWalker.cs
- StickyNote.cs
- ValidatorCompatibilityHelper.cs
- GacUtil.cs
- BuildManagerHost.cs
- BitStack.cs
- TextBox.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- TimeSpan.cs
- ChtmlFormAdapter.cs