如何创建PFX / CER一个SNK?PFX、CER、SNK

由网友(Cleanliness(干净))分享简介:微软似乎已经创建了一个认证的丛林,这是很难理解的。在微软的X.509证书(.cer)个人信息交换(.pfx)大会签名密钥属性(.SNK)难道是建议创建以PFX或CER的SNK文件?(不知道它甚至有可能,如果其可能是如何做的?) 虽然装配可以用密码保护的PFX签名,它似乎并没有被强大的命名虽然,除非它与SNK签约...

微软似乎已经创建了一个认证的丛林,这是很难理解的。

在微软的X.509证书(.cer) 个人信息交换(.pfx)

大会签名密钥属性(.SNK)

难道是建议创建以PFX或CER的SNK文件? (不知道它甚至有可能,如果其可能是如何做的?)

虽然装配可以用密码保护的PFX签名,它 似乎并没有被强大的命名虽然,除非它与SNK签约 代替。但SNK并没有密码保护。哪一个更安全 使用?正如我在我的项目的唯一开发商,我没有 多开发saftey环境问题,但还是想 知道什么是最好的办法。

非常感谢,

解决方案

你提到的文件类型有一点说明:

的 .CER 的-files是X.509证书 的的.pfx 的-files加密使用的是基于密码的对称密钥X.509证书,也看到 PKCS#12(维基百科) 的 .SNK 的-files只包含RSA密钥(公钥/私钥或公共只)

这并不重要,如果你使用签名的程序集的的.pfx 的-files或 .SNK 的-files,它会被强命名两种方式无所谓。 存储RSA密钥作为加密的证书( .PFX 的),当然不是存储只是未加密的密钥更安全(的 .SNK 的)。

您可以通过方便地提取从code这些文件中的重点班 System.Security.Cryptography.X509Certificates.X509Certificate2

要提取的的.pfx 的键:

  ///<总结>
/// .pfx文件到.snk文件转换。
///< /总结>
///< PARAM NAME =pfxData> .pfx文件数据和LT; /参数>
///< PARAM NAME =pfxPassword> .pfx文件的密码< /参数>
///<返回> .snk文件数据和LT; /回报>
公共静态的byte [] Pfx2Snk(byte []的pfxData,串pfxPassword)
{
    //负荷.PFX
    VAR证书=新X509Certificate2(pfxData,pfxPassword,X509KeyStorageFlags.Exportable);

    //创建.SNK
    VAR privateKey =(的RSACryptoServiceProvider)cert.PrivateKey;
    返回privateKey.ExportCspBlob(真);
}
 

使用 privateKey.ExportCspBlob(假)只提取公钥! (例如,对于延迟签约组件)

PFX拿到冠军后竟然没有皮肤 LPL做出回应,IG的含金量更高一些

Microsoft seems to have created a certification jungle, that is hard to understand.

Microsoft X.509 certificate (.cer) Personal Information Exchange (.pfx)

Assembly Signature Key Attribute (.snk)

Would it be advisable to create an snk file based on pfx or cer? (Not sure if its even possible, and if its possible how is it done?)

While an assembly can be signed with a password protected pfx, it doesn't seem to be strong named though, unless it is signed with snk instead. But the snk has no password protection. Which one is safer to use? As I am the only developer in my project, I don't have the multi-developer saftey environment issue, but still would like to know what is best approach.

Many Thanks,

解决方案

A little clarification about your mentioned file types:

.cer-files are X.509 Certificates .pfx-files are encrypted X.509 Certificates using a password-based symmetric key, also see PKCS #12 (Wikipedia) .snk-files only contain the RSA key (public/private or public only)

It doesn't matter if you sign an assembly using .pfx-files or .snk-files, it will get strong named either way. Storing the RSA key as a encrypted certificate (.pfx) is of course more secure than storing just the unencrypted key (.snk).

You can easily extract the key from those files in code using class System.Security.Cryptography.X509Certificates.X509Certificate2.

To extract key from .pfx:

/// <summary>
/// Converts .pfx file to .snk file.
/// </summary>
/// <param name="pfxData">.pfx file data.</param>
/// <param name="pfxPassword">.pfx file password.</param>
/// <returns>.snk file data.</returns>
public static byte[] Pfx2Snk(byte[] pfxData, string pfxPassword)
{
    // load .pfx
    var cert = new X509Certificate2(pfxData, pfxPassword, X509KeyStorageFlags.Exportable);

    // create .snk
    var privateKey = (RSACryptoServiceProvider)cert.PrivateKey;
    return privateKey.ExportCspBlob(true);
}

Use privateKey.ExportCspBlob(false) to extract public key only! (e.g. for delay-signing of assemblies)

阅读全文

相关推荐

最新文章