开发者

How to import an .snk file generated with sn.exe in .NET?

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.


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();
    }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜