2015-05-19 68 views
0

我正在使用RSACryptoServiceProvider來提高安全性。如何使用指紋來保證安全?

我使用自簽名證書構建了代碼以用於測試目的。 不是用戶向我們提供了實際的指紋。 我期待取得證書嗎? 如何使用指紋?

這裏是代碼:

/// Builds Authorization in using self signed certificate 
/// </summary> 
/// <returns></returns> 
private string BuildAuthorization() 
{ 
    X509Certificate2 cert = GetCertificate(); 

    RSACryptoServiceProvider provideEncryptor = (RSACryptoServiceProvider)cert.PublicKey.Key; 

    string authorizaionValue = string.Format("{0}:{1}:{2}", _userName,_password, _currentTime); 

    byte[] encryptedData = provideEncryptor.Encrypt(Encoding.UTF8.GetBytes(authorizaionValue), false); 

    string encryptedString = Convert.ToBase64String(encryptedData); 

    return encryptedString; 

} 


/// <summary> 
/// creates a self signed certificate 
/// </summary> 
/// <returns></returns> 
private X509Certificate2 GetCertificate() 
{ 
    X509Store store = new X509Store(StoreLocation.CurrentUser); 
    store.Open(OpenFlags.ReadOnly); 
    X509Certificate2 cert = null; 
    string certName = ConfigurationManager.AppSettings["CertName"]; 

    foreach (var c in store.Certificates) 
    { 
     if (c.Subject.Equals(certName, StringComparison.OrdinalIgnoreCase)) 
     { 
      cert = c; 
      break; 
     } 
    } 


    store.Close(); 

    return cert; 

} 

提供的指紋是一樣的東西:

87aa7f6 ******************** 9b2d95093a6

+0

AnyOne有什麼想法是什麼意思? – grace

+1

我找到了一個解決方案,請檢查 http://stackoverflow.com/questions/11115511/how-to-find-certificate-by-its-thumbprint-in-c-sharp – Nazmul

回答

1

指紋只是證書的標識符,通常是證書的MD5或SHA1散列。

你不能真正對指紋本身做任何事情,把它想象成數據庫中記錄的ID。您需要確定,但是我懷疑他們的意圖是他們正在給您的證書存儲區中的證書指紋。 This StackOverflow question提供了有關如何通過指紋從證書存儲區加載證書的信息。

+0

謝謝!現在它更有意義。 – grace

+0

這裏是東西,只要你在本地的證書,基於指紋搜索的代碼是好的。我張貼在外部網址上?我如何搜索他們的證書?它將我扔到'X509Store certStore = new X509Store(StoreName.My,StoreLocation.CurrentUser);' – grace

相關問題