PFX/PKCS12 to SNK conversion for mono

后端 未结 3 713
甜味超标
甜味超标 2021-01-05 17:24

This is follow up on Mono xbuild error CS1548 - key file has incorrect format

Hi, I have an application that is written in C# using VS2008. At present we are porting

3条回答
  •  一生所求
    2021-01-05 18:10

    Big thanks Poupou for coming up with the answer I have just added the code to the little program I made to get my snk.

    using System.IO;
    using System.Security.Cryptography;
    using System.Security.Cryptography.X509Certificates;
    
    namespace PfxSnk
    {
        internal class Program
        {
            private static void Main(string[] args)
            {
                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);
                }
            }
        }
    }
    

提交回复
热议问题