我有以下代码和应用程序有时成功,但对于某些用户它无法解密密码。它主要发生在服务器和多用户环境,在开发机器上效果很好。受保护的数据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范围工作正常..感谢 –