Export (0) Print
Expand All

StrongNameKeyPair Class

Encapsulates access to a public or private key pair used to sign strong name assemblies.

System::Object
  System.Reflection::StrongNameKeyPair

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class StrongNameKeyPair : IDeserializationCallback, 
	ISerializable

The StrongNameKeyPair type exposes the following members.

  NameDescription
Public methodStrongNameKeyPair(array<Byte>)Initializes a new instance of the StrongNameKeyPair class, building the key pair from a byte array.
Public methodStrongNameKeyPair(FileStream)Initializes a new instance of the StrongNameKeyPair class, building the key pair from a FileStream.
Public methodStrongNameKeyPair(String)Initializes a new instance of the StrongNameKeyPair class, building the key pair from a String.
Protected methodStrongNameKeyPair(SerializationInfo, StreamingContext)Initializes a new instance of the StrongNameKeyPair class, building the key pair from serialized data.
Top

  NameDescription
Public propertyPublicKeyGets the public part of the public key or public key token of the key pair.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIDeserializationCallback::OnDeserializationRuns when the entire object graph has been deserialized.
Explicit interface implemetationPrivate methodISerializable::GetObjectDataSets the SerializationInfo object with all the data required to reinstantiate the current StrongNameKeyPair object.
Top

The following code example shows how to open a Company.keys file (produced by running the Sn.exe (Strong Name Tool) with the –k switch), read the public key from the file, and display the key in the console window.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;

ref class snkX
{
public:
    static void Main()
    {
        // Open a file that contains a public key value. The line below   
        // assumes that the Strong Name tool (SN.exe) was executed from  
        // a command prompt as follows: 
        //       SN.exe -k C:\Company.keys
        FileStream^ fs = File::Open("C:\\Company.keys", FileMode::Open);

        // Construct a StrongNameKeyPair object. This object should obtain 
        // the public key from the Company.keys file.
        StrongNameKeyPair^ k = gcnew StrongNameKeyPair(fs);

        // Display the bytes that make up the public key.
        Console::WriteLine(BitConverter::ToString(k->PublicKey));

        // Close the file.
        fs->Close();
    }
};

int main()
{
    snkX::Main();
}

// Output will vary by user. 
//  
//  00-24-00-00-04-80-00-00-94-69-89-78-BB-F1-F2-71-00-00-00-34-26- 
//  69-89-78-BB-F1-F2-71-00-F1-FA-F2-F9-4A-A8-5E-82-55-AB-49-4D-A6- 
//  ED-AB-5F-CE-DE-59-49-8D-63-01-B0-E1-BF-43-07-FA-55-D4-36-75-EE- 
//  8B-83-32-39-B7-02-DE-3D-81-29-7B-E8-EA-F0-2E-78-94-96-F1-73-79- 
//  69-89-78-BB-F1-F2-71-0E-4E-F4-5D-DD-A4-7F-11-54-DF-65-DE-89-23- 
//  91-AD-53-E1-C0-DA-9E-0C-88-BE-AA-7B-39-20-9C-9B-55-34-26-3B-1A- 
//  53-41-31-00-04-00-00-01-00-01-00-9D-F1-EA-14-4C-88-34-26-3B-1A- 
//  2D-D7-A0-AB-F6-7E-B7-24-7F-87-DF-3E-97

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft