Microsoft seems to have created a certification jungle, that is hard to understand.
Assembly Signature Key Attribute (.snk)
Would it be advisable to create an snk file based on pfx or cer? (Not sure if its even possible, and if its possible how is it done?)
While an assembly can be signed with a password protected pfx, it doesn't seem to be strong named though, unless it is signed with snk instead. But the snk has no password protection. Which one is safer to use? As I am the only developer in my project, I don't have the multi-developer saftey environment issue, but still would like to know what is best approach.
Many Thanks,
Simply right click the pfx file, click "Install" follow the wizard, and add it to a store (I added to the Personal store). In start menu type certmgr. msc and go to CertManager program.
Software key file created by Strong Name Tool (Sn.exe), a cryptographic program included with Microsoft's . NET framework; contains a public key and private key pair; used to digitally sign and authenticate an application.
pfx includes both the public and private key for the associated certificate, so don't share this outside your organization. A . cer file only has the public key, it includes the public key, the server name, some extra information about the server. This is what you typically exchange with your partners.
A little clarification about your mentioned file types:
It doesn't matter if you sign an assembly using .pfx-files or .snk-files, it will get strong named either way. Storing the RSA key as a encrypted certificate (.pfx) is of course more secure than storing just the unencrypted key (.snk).
You can easily extract the key from those files in code using class System.Security.Cryptography.X509Certificates.X509Certificate2
.
/// <summary> /// Converts .pfx file to .snk file. /// </summary> /// <param name="pfxData">.pfx file data.</param> /// <param name="pfxPassword">.pfx file password.</param> /// <returns>.snk file data.</returns> public static byte[] Pfx2Snk(byte[] pfxData, string pfxPassword) { // load .pfx var cert = new X509Certificate2(pfxData, pfxPassword, X509KeyStorageFlags.Exportable); // create .snk var privateKey = (RSACryptoServiceProvider)cert.PrivateKey; return privateKey.ExportCspBlob(true); }
Use privateKey.ExportCspBlob(false)
to extract public key only! (e.g. for delay-signing of assemblies)
To generate a snk file with solely the public key from a pfx:
sn -p keypair.pfx key.snk
I have always been a fan of using snk files over .pfx files they just seem less buggy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With