views:

28

answers:

2

I have created a key file with this command:


 sn.exe -k 2048 Build.snk

I would like to read in this key with .NET. I haven't been able to find any document as to the format of the .snk, so I'm wondering if there's a way in C# to read in an .snk file?

My original reason for asking the question was to use the .snk file for purposes other than signing an assembly. As one of the answers states below, the purpose of .snk files is really just for signing assemblies.

+1  A: 

Strong naming keys are used at compile-time to sign the assemblies produced by the compiler--so reading them in during runtime probably isn't what you want.

To get started look for the "Signing" tab in your C# Project's Properties window--there you can choose what .snk to sign the assembly with.

http://msdn.microsoft.com/en-us/library/xc31ft41(VS.100).aspx

STW
+1  A: 

Found a mention in MSDN here. Here's the code:


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
    using (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 = new StrongNameKeyPair(fs);

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

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

Steve Wranovsky