2009-08-07 24 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

相关问题