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

时间:2019-08-28 16:35:28

标签: cryptography rsa x509certificate2 hsm cng

我有自己的CNG提供者。在带有窗口7的.net Framework 4.6.1中使用c#。我正在使用clrsecurity

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

cngKey的属性: enter image description here

问题是我无法将提供程序名称设置为CngKey对象。 那么如何将clrsecurity dll用于非Microsoft KSP。

0 个答案:

没有答案