PFX/PKCS12到SNK的单声道转换 [英] PFX/PKCS12 to SNK conversion for mono

查看:129
本文介绍了PFX/PKCS12到SNK的单声道转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对> xobuild错误CS1548-键的后续操作文件格式错误

我有一个使用VS2008用C#编写的应用程序.目前,我们正在使用Mono将这个应用程序移植到Mac.

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

我试图从pfx文件中提取密钥. 首先,我用

I have tried to extract the key from the pfx file. First I used

`sn -pc key.pfx key.snk`

这给我一个

'Failed to extract public key for key pair -- Keyset does not exist'.

然后我用

`sn -p key.pfx key.snk`

这创建了我想要的snk文件. 然后,我以单声道方式选择了项目选项">程序集签名" 建立错误

this created the snk file that I wanted. I then in mono selected the project Option > Assembly Signing When built the error

'key.snk is missing private key needed for signing'.

我想我知道,如果我创建一个新的snk密钥,则可以同时包含私钥和公钥.只是由于遗留问题,我们真的希望能够使用原始pfx键值.

I think I understand that if I make a new snk key that I can have both private and public keys in it. It just that because of Legacy issues we would really like to be able to use the original pfx key values.

推荐答案

非常感谢Poupou提出的答案,我刚刚将代码添加到了为获取SNK而编写的小程序中.

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

这篇关于PFX/PKCS12到SNK的单声道转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆