views:

33

answers:

1

As the title states, does anyone know how to extract the private key from an snk file? We want to use the private key from the StrongName for encryption purposes. I read in:
http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx that sn -o key.snk will extract both the private/public key if they exist in the file but i tried it and its just a long CSV formatted string with no distinction between what is the private key and what is the public key.

A: 

In the document you link, next to the -o flag, it says:

If the infile contains a key pair with a private key, the private key is also extracted.

Are you certain there is a private key in the file?

You can run sn -p key.snk to get the public key, and compare that to the output of sn -o key.snk - if they are the same, the key file only has a public key, if not, the difference is the private key.

Oded
yep just created it as follows:sn -k key.snk. Strong name files always have a public/private key combo otherwise it wouldn't work for signing assemblies.
@user127954 - then extract the public key only and compare. See updated answer.
Oded
While possible its going to be a pain because the -o option returns a byte array while -p returns string of gibberish :). Well i guess not that hard but i'll have to create a program to read it in and convert it into a byte array. I'm suprised there is no documented way to return the private key.
@user127954 - Probably because it is supposed to be **private**. You should remember what you used when creating the key file...
Oded
Yes i totally understand that but there are other formats for public/private key pairs. For example pfx you can easily extract the private key. Saying you can't extract the private key because its private doesn't really make sense. If someone has your snk file all hope is lost and they could easily sign their own code and replace one of your assemblies and your program would never know its rogue code. Heck maybe i'll just end up hashing the snk file and use that as the key and call it a day.