chore: SimpleEncryptionHelper 新增 DataProtectionScope 参数

This commit is contained in:
uye
2025-01-19 23:06:49 +08:00
parent 70cefeb99c
commit 2d367b55e3

View File

@@ -9,7 +9,7 @@ public static class SimpleEncryptionHelper
{
private static readonly ILogger _logger = Log.ForContext("SourceContext", "SimpleEncryptionHelper");
public static string Encrypt(string plainText)
public static string Encrypt(string plainText, DataProtectionScope dataProtectionScope = DataProtectionScope.CurrentUser)
{
if (string.IsNullOrEmpty(plainText))
{
@@ -19,7 +19,7 @@ public static class SimpleEncryptionHelper
try
{
var data = Encoding.UTF8.GetBytes(plainText);
var encryptedData = ProtectedData.Protect(data, null, DataProtectionScope.CurrentUser);
var encryptedData = ProtectedData.Protect(data, null, dataProtectionScope);
return Convert.ToBase64String(encryptedData);
}
catch (Exception e)
@@ -29,7 +29,7 @@ public static class SimpleEncryptionHelper
}
}
public static string Decrypt(string encryptedText)
public static string Decrypt(string encryptedText, DataProtectionScope dataProtectionScope = DataProtectionScope.CurrentUser)
{
if (string.IsNullOrEmpty(encryptedText))
{
@@ -39,7 +39,7 @@ public static class SimpleEncryptionHelper
try
{
var data = Convert.FromBase64String(encryptedText);
var decryptedData = ProtectedData.Unprotect(data, null, DataProtectionScope.CurrentUser);
var decryptedData = ProtectedData.Unprotect(data, null, dataProtectionScope);
return Encoding.UTF8.GetString(decryptedData);
}
catch (Exception e)