What is a .snk for?

webdtc picture webdtc · Sep 25, 2008 · Viewed 90.4k times · Source

What is a .snk file for? I know it stands for Strongly Named Key, but all explanations of what it is and how it works goes over my head.

Is there any simple explanation on how a strongly named key is used and how it works?

Answer

Blair Conrad picture Blair Conrad · Sep 25, 2008

The .snk file is used to apply a strong name to a .NET assembly. such a strong name consists of

a simple text name, version number, and culture information (if provided)—plus a public key and a digital signature.

The SNK contains a unique key pair - a private and public key that can be used to ensure that you have a unique strong name for the assembly. When the assembly is strongly-named, a "hash" is constructed from the contents of the assembly, and the hash is encrypted with the private key. Then this signed hash is placed in the assembly along with the public key from the .snk.

Later on, when someone needs to verify the integrity of the strongly-named assembly, they build a hash of the assembly's contents, and use the public key from the assembly to decrypt the hash that came with the assembly - if the two hashes match, the assembly verification passes.

It's important to be able to verify assemblies in this way to ensure that nobody swaps out an assembly for a malicious one that will subvert the whole application. This is why non-strong-named assemblies aren't trusted in the same way that strongly-named assemblies are, so they can't be placed in the GAC. Also, there's a chain of trust - you can't generate a strongly-named assembly that references non-strongly-named assemblies.

The article "The Secrets of Strong Naming (archived at the Wayback Machine)". Does an excellent job of explaining these concepts in more detail. With pictures.