Cryptography 使用自定义CNG提供程序从HSM获取私钥

Cryptography 使用自定义CNG提供程序从HSM获取私钥,cryptography,rsa,x509certificate2,hsm,cng,Cryptography,Rsa,X509certificate2,Hsm,Cng,我有自己的CNG供应商。将c#与.NETFramework 4.6.1结合使用,并在Windows7中使用。我正在使用 cngKey的属性: 问题是我无法将提供者名称设置为CngKey对象。 因此,如何为非Microsoft KSP使用clrsecurity dll。不支持clrsecurity项目,您应该只使用最终产品版本(注释掉的cert.GetRSAPrivateKey())。但无论哪种方式,答案都是它使用证书的cert\u KEY\u PROV\u INFO\u PROP\u ID属性

我有自己的CNG供应商。将c#与.NETFramework 4.6.1结合使用,并在Windows7中使用。我正在使用

cngKey的属性:

问题是我无法将提供者名称设置为CngKey对象。
因此,如何为非Microsoft KSP使用clrsecurity dll。

不支持clrsecurity项目,您应该只使用最终产品版本(注释掉的cert.GetRSAPrivateKey())。但无论哪种方式,答案都是它使用证书的
cert\u KEY\u PROV\u INFO\u PROP\u ID
属性说要使用的任何KSP。GetRSAPrivateKey()是否适用于自定义CNG提供商?
GetRSAPrivateKey
将使用(本机)证书属性说要使用的任何KSP。它不假设任何东西(或者智能卡和网络HSM可能不起作用)。RSA对象可以解密,但当我看到RSA对象的属性时,仍然存在异常。不支持clrsecurity项目,您应该只使用最终产品版本(注释掉的cert.GetRSAPrivateKey())。但无论哪种方式,答案都是它使用证书的
cert\u KEY\u PROV\u INFO\u PROP\u ID
属性说要使用的任何KSP。GetRSAPrivateKey()是否适用于自定义CNG提供商?
GetRSAPrivateKey
将使用(本机)证书属性说要使用的任何KSP。它不假设任何东西(或者智能卡和网络HSM可能不起作用)。RSA对象解密很好,但当我看到RSA对象的属性时,仍然有例外。
string fp = "223298a5c7c9f78a42d83a5ffbxxxxxxxx";
//string fp = "331ffa497d90d19446171f85xxxxxxxx"; //MS
// Load the certificate with the specified serial number
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certificates = store.Certificates.Find(X509FindType.FindBySerialNumber, fp, false);

// check if at least one certificate has been found
if (certificates.Count != 1)
{
    throw new Exception("The certificate with the serial number " + fp + " could not be found.");
}

X509Certificate2 cert = certificates[0];
CngKey cngKey = null;
if (cert.HasCngKey())
{
    //rsa = cert.GetRSAPrivateKey();                   
    cngKey = cert.GetCngPrivateKey();
}