如何在Windows应用商店应用中获取证书的字节数组

时间:2014-05-15 08:44:21

标签: c# .net windows-runtime windows-store-apps certificate

在.NET中,有一种方法可用于获取证书的字节数组。但是,在Windows应用商店应用中,您将找不到此Export()方法...

这是它在常规.NET中的完成方式:

// .NET 4.5
X509Certificate cert = new X509Certificate("path/to/cert.pfx");
byte[] certData = cert.Export(X509ContentType.Cert);



如何在Windows应用商店应用中将证书导出为字节数组?

1 个答案:

答案 0 :(得分:2)

.NET for Windows Store应用程序中有一种新方法: Certificate.GetCertificateBlob()
它返回一个BLOB,然后您可以将其转换为数组以获取字节数组

// get certificate with given Friendly Name
var query = new CertificateQuery { FriendlyName = "certFriendlyName" };
certList = await CertificateStores.FindAllAsync(query);
Certificate cert = certList.First();

// get the BLOB of the certificate and transform it to byte[]
var blob = cert.GetCertificateBlob();
byte[] certData = blob.ToArray();

另请查看此处了解更多信息:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.cryptography.certificates.certificate.getcertificateblob