Dot-Net
在 Windows 應用程序中保存使用者憑據
是否有在 .NET Windows 應用程序中儲存憑據的最佳實踐方法,無論是內置 API 還是推薦的加密算法?
與 Tortoise SVN、Spotify 和 Skype 類似。
**編輯:**我的意圖是使用從其身份驗證服務返回令牌的 Web 服務。然後其他服務接受該令牌作為參數。但是,令牌會在 30 分鐘後過期,因此儲存令牌本身對這項任務毫無意義。
看來使用ProtectedData(包裝了Windows 數據保護 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);