2012-02-10 51 views
2

我正在使用使用vc 6.0和cryptoAPI创建的密钥库。密钥库包含所有交换/签名密钥。所以我可以使用公钥来很好地使用RSA加密数据,但是当签名或解密数据时,我似乎找不到如何使用私钥解密。如何使用c#对散列进行签名和加密只给定一个密钥库

我见过很多网站使用 rsa =(RSACryptoServiceProvider)cert.PrivateKey;

但在我的密钥库中,当我查看证书时,所有私钥都不存在。

//这是我怎么设置商店

public cryptTest(string storeName) 
{ 
    store = new X509Store(storeName); 
    this.storename = storename; 
} 

//这是我从店里拿到证书

public X509Certificate2 getCertificate(string ID, certType ct) 
{ 
    if (store == null) 
    { 
     return null; 
    } 
    store.Open(OpenFlags.ReadOnly); 
    foreach (X509Certificate2 cert in store.Certificates) 
    { 
     if ((ct == certType.exchange && cert.Subject.Contains("Exchange")) || 
      (ct == certType.signature && cert.Subject.Contains("Signature"))) 
     { 
      if (cert.Subject.Contains(ID)) // if the ID match 
      { 
       // todo check date etc ! is cert still valid if not delete etc. 
       store.Close(); 
       return cert; 
      } 
     } 
    } 
    store.Close(); 
    return null; 
} 

但随后在证书他们从未有一个私钥,那么我怎么可能使用密钥库中的证书解密或签名?

非常感谢!

回答

相关问题