如何从* .pfx文件导出* .p7b证书

时间:2014-06-05 08:38:04

标签: windows-phone-8 certificate pkcs#7

MSDN说: X509Certificate.Export contentType参数仅接受X509ContentType枚举的以下值:Cert,SerializedCert和Pkcs12。传递任何其他值会导致抛出CryptographicException。 http://msdn.microsoft.com/en-us/library/dxz81eb9(v=vs.110).aspx

还有其他方法吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

最近,我了解.p7b格式是什么。

static void ExportCert()
{
        X509Certificate2 x509 = new X509Certificate2(@"E:\SimonSelf.pfx", "password", X509KeyStorageFlags.Exportable);

        X509Certificate2Collection x509List = new X509Certificate2Collection(x509);
        byte[] p7bBinary = x509List.Export(X509ContentType.Pkcs7);
        using (FileStream fs = new FileStream(@"E:\SimonSelf.p7b", FileMode.Create))
        {
            fs.Write(p7bBinary, 0, p7bBinary.Length);
            fs.Close();
        }
}