Skip to content

Instantly share code, notes, and snippets.

@hongz1
Forked from baywet/pfxtosnk.cs
Created December 7, 2016 21:39
Show Gist options
  • Save hongz1/b289c5534973c9e2e2ee36809887a440 to your computer and use it in GitHub Desktop.
Save hongz1/b289c5534973c9e2e2ee36809887a440 to your computer and use it in GitHub Desktop.
sample on how to convert a pfx to snk visual studio assembly signing certificate
X509Certificate2 cert = new X509Certificate2(@"KEY.pfx", "pfxPassword", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
RSACryptoServiceProvider provider = (RSACryptoServiceProvider) cert.PrivateKey;
byte[] array = provider.ExportCspBlob(!provider.PublicOnly);
using (FileStream fs = new FileStream("FileName.snk", FileMode.Create, FileAccess.Write))
{
fs.Write(array, 0, array.Length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment