How to import .snk file generated by sn.exe into .NET?

I created a key file with this command:


 sn.exe -k 2048 Build.snk

I would like to read this key using .NET. I could not find any document regarding the .snk format, so I wonder if there is a way in C # to read in the .snk file?

My initial reason for asking the question was to use the .snk file for purposes other than signing the assembly. As one answer says, the purpose of .snk files is only for signing assemblies.

+3
source share
2 answers

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

+9

Source: https://habr.com/ru/post/1751250/


All Articles