如何导入在.NET中使用sn.exe生成的.snk文件?

Ste*_*sky 3 .net c# encryption sn.exe

我用这个命令创建了一个密钥文件:


 sn.exe -k 2048 Build.snk

我想用.NET阅读这个密钥.我无法找到任何关于.snk格式的文档,所以我想知道C#中是否有一种读取.snk文件的方法?

我提出问题的原因是将.snk文件用于签署程序集以外的目的.作为下面的答案之一,.snk文件的目的实际上只是用于签署程序集.

Ste*_*sky 9

发现在MSDN一提这里.这是代码:


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