我有以下代碼和應用程序有時成功,但對於某些用戶它無法解密密碼。它主要發生在服務器和多用戶環境,在開發機器上效果很好。受保護的數據API問題
public static byte [] Protect(byte [] data)
{
try
{
// Encrypt the data using DataProtectionScope.CurrentUser. The result can be decrypted
// only by the same current user.
return ProtectedData.Protect(data, s_aditionalEntropy, DataProtectionScope.CurrentUser);
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not encrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}
public static byte [] Unprotect(byte [] data)
{
try
{
//Decrypt the data using DataProtectionScope.CurrentUser.
return ProtectedData.Unprotect(data, s_aditionalEntropy, DataProtectionScope.CurrentUser);
}
catch (CryptographicException e)
{
Console.WriteLine("Data was not decrypted. An error occurred.");
Console.WriteLine(e.ToString());
return null;
}
}
按代碼DataProtectionScope.CurrentUser其用戶特定的,以便確保在多用戶環境中,其保護方法被稱爲實例的每個用戶登錄。我的建議是驗證問題變更範圍DataProtectionScope.LocalMachine和驗證,然後您可以確認 –
感謝您的快速回復讓我檢查 –
@sumeet kumar:LocalMachine範圍工作正常..感謝 –