PFX/PKCS12 to SNK conversion for mono

萝らか妹 提交于 2019-11-30 20:26:35
Paul Williams

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);
            }
        }
    }
}

sn -pis used to extract a public key from a strongname.

However you need the private key in order to sign an assembly - so this (built-in sn) conversion is not helpful for your goal.

Sadly a quick look at Microsoft sn options does not document any option to do what you're looking for.

My suggestion is to write a small tool, re-using Mono sn and Mono.Security.dll source code, to read the PFX (pkcs#12) file and write it back as a SNK file.

Larry

Try sn -p key.pfx key.snk instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!