2009-08-07 71 views
6

是否存在將憑據存儲在.NET Windows應用程序中的最佳實踐方式,無論是內置的API還是推薦的加密算法?在Windows應用程序中保存用戶憑據

與Tortoise SVN,Spotify和Skype一樣。

編輯:我的意圖是使用Web服務從其身份驗證服務返回一個令牌。其他服務然後接受該令牌作爲參數。但是,令牌在30分鐘後過期,因此存儲令牌本身對此任務毫無意義。

+0

以防萬一您以前沒有遇到過:[設計驗證系統: 四場景對話](http://web.mit.edu /kerberos/www/dialogue.html)是一篇關於Kerberos原理的偉大文章;我認爲在創建身份驗證服務的過程中可能會很有趣。 – Regent 2010-09-06 17:56:36

回答

12

看來使用ProtectedData(其中包含Windows Data Protection API)是我最好的選擇,因爲它可以根據當前登錄的用戶進行加密。

byte[] dataToEncrypt = new byte[] { ... }; 

// entropy will be combined with current user credentials 
byte[] additionalEntropy = new byte { 0x1, 0x2, 0x3, 0x4 }; 

byte[] encryptedData = ProtectedData.Protect(
    dataToEncrypt, additionalEntropy, DataProtectionScope.CurrentUser); 

byte[] decryptedData = ProtectedData.Unprotect(
    encryptedData, additionalEntropy, DataProtectionScope.CurrentUser); 
0

最佳做法是永遠不要存儲憑據,只有Kerberos令牌......不幸的是,並非每個資源都允許這種身份驗證。

+0

我應該更具體。查看我的更新。 – 2009-08-07 07:16:38

0

在MSDN中有很多recomendations重新密碼。您需要找到一個管理包裝CryptProtectData

+1

System.Security.Cryptography.ProtectedData *是一個用於CryptProtectedData的託管包裝。看到我上面的答案。 – 2009-08-07 07:47:52

相關問題