Advertisement
Guest User

Untitled

a guest
Apr 30th, 2012
1,680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. PFX/PKCS12 to SNK conversion for mono
  2. `sn -pc key.pfx key.snk`
  3.  
  4. 'Failed to extract public key for key pair -- Keyset does not exist'.
  5.  
  6. `sn -p key.pfx key.snk`
  7.  
  8. 'key.snk is missing private key needed for signing'.
  9.  
  10. // libs used
  11. using System.Security.Cryptography;
  12. using System.Security.Cryptography.X509Certificates;
  13. using Mono.Security;
  14.  
  15. //code needs to be put in a method
  16. X509Certificate2 cert = new X509Certificate2(@"KEY.pfx", "pfxPassword", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
  17. RSACryptoServiceProvider provider = (RSACryptoServiceProvider) cert.PrivateKey;
  18.  
  19. byte[] array = provider.ExportCspBlob(!provider.PublicOnly);
  20.  
  21. using (FileStream fs = new FileStream("FileName.snk", FileMode.Create, FileAccess.Write))
  22. {
  23. fs.Write(array, 0, array.Length);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement