【问题标题】:Saving user credentials in a Windows application在 Windows 应用程序中保存用户凭据
【发布时间】:2009-08-07 07:13:37
【问题描述】:

是否有在 .NET Windows 应用程序中存储凭据的最佳实践方法,无论是内置 API 还是推荐的加密算法?

与 Tortoise SVN、Spotify 和 Skype 类似。

编辑: 我的意图是使用一个从其身份验证服务返回令牌的 Web 服务。然后其他服务接受该令牌作为参数。但是,令牌会在 30 分钟后过期,因此存储令牌本身对这项任务毫无意义。

【问题讨论】:

标签: .net windows security authentication


【解决方案1】:

看来使用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);

【讨论】:

    【解决方案2】:

    最好的做法是永远不要存储凭据,只存储 Kerberos 令牌......不幸的是,并非每个资源都允许这种身份验证。

    【讨论】:

      【解决方案3】:

      MSDN 中有很多recomendations re 密码。您将需要为CryptProtectData 找到一个托管包装器

      【讨论】:

      • System.Security.Cryptography.ProtectedData CryptProtectedData 的托管包装器。见我上面的回答。
      猜你喜欢
      • 1970-01-01
      • 2016-10-27
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多