在Windows应用程序中保存用户凭据

Ric*_*lay 8 .net windows security authentication

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

与Tortoise SVN,Spotify和Skype一样.

编辑:我的目的是使用从其身份验证服务返回令牌的Web服务.然后其他服务接受该标记作为参数.但是,令牌在30分钟后到期,因此存储令牌本身对于此任务毫无意义.

Ric*_*lay 14

看来使用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);
Run Code Online (Sandbox Code Playgroud)