diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj
index 2dbad072b..b4b6cdef0 100644
--- a/ArchiSteamFarm/ArchiSteamFarm.csproj
+++ b/ArchiSteamFarm/ArchiSteamFarm.csproj
@@ -89,6 +89,7 @@
+
diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs
index 778194cb0..76c909309 100755
--- a/ArchiSteamFarm/Bot.cs
+++ b/ArchiSteamFarm/Bot.cs
@@ -548,7 +548,9 @@ namespace ArchiSteamFarm {
return "Can't encrypt null password!";
}
- return CryptoHelper.ECryptoMethod.AES + "-encrypted password: " + CryptoHelper.Encrypt(CryptoHelper.ECryptoMethod.AES, BotConfig.SteamPassword);
+ return Environment.NewLine +
+ "[" + CryptoHelper.ECryptoMethod.AES + "] password: " + CryptoHelper.Encrypt(CryptoHelper.ECryptoMethod.AES, BotConfig.SteamPassword) + Environment.NewLine +
+ "[" + CryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser + "] password: " + CryptoHelper.Encrypt(CryptoHelper.ECryptoMethod.ProtectedDataForCurrentUser, BotConfig.SteamPassword);
}
private static string ResponsePassword(ulong steamID, string botName) {
diff --git a/ArchiSteamFarm/CryptoHelper.cs b/ArchiSteamFarm/CryptoHelper.cs
index 8d225dc0d..bea0f6bae 100644
--- a/ArchiSteamFarm/CryptoHelper.cs
+++ b/ArchiSteamFarm/CryptoHelper.cs
@@ -30,7 +30,8 @@ namespace ArchiSteamFarm {
internal static class CryptoHelper {
internal enum ECryptoMethod : byte {
PlainText,
- AES
+ AES,
+ ProtectedDataForCurrentUser
}
private static readonly byte[] EncryptionKey = Encoding.UTF8.GetBytes("ArchiSteamFarm");
@@ -46,6 +47,8 @@ namespace ArchiSteamFarm {
return decrypted;
case ECryptoMethod.AES:
return EncryptAES(decrypted);
+ case ECryptoMethod.ProtectedDataForCurrentUser:
+ return EncryptProtectedDataForCurrentUser(decrypted);
default:
return null;
}
@@ -62,6 +65,8 @@ namespace ArchiSteamFarm {
return encrypted;
case ECryptoMethod.AES:
return DecryptAES(encrypted);
+ case ECryptoMethod.ProtectedDataForCurrentUser:
+ return DecryptProtectedDataForCurrentUser(encrypted);
default:
return null;
}
@@ -108,5 +113,45 @@ namespace ArchiSteamFarm {
return null;
}
}
+
+ private static string EncryptProtectedDataForCurrentUser(string decrypted) {
+ if (string.IsNullOrEmpty(decrypted)) {
+ Logging.LogNullError(nameof(decrypted));
+ return null;
+ }
+
+ try {
+ byte[] encryptedData = ProtectedData.Protect(
+ Encoding.UTF8.GetBytes(decrypted),
+ EncryptionKey, // This is used as salt only
+ DataProtectionScope.CurrentUser
+ );
+
+ return Convert.ToBase64String(encryptedData);
+ } catch (Exception e) {
+ Logging.LogGenericException(e);
+ return null;
+ }
+ }
+
+ private static string DecryptProtectedDataForCurrentUser(string encrypted) {
+ if (string.IsNullOrEmpty(encrypted)) {
+ Logging.LogNullError(nameof(encrypted));
+ return null;
+ }
+
+ try {
+ byte[] decryptedData = ProtectedData.Unprotect(
+ Convert.FromBase64String(encrypted),
+ EncryptionKey, // This is used as salt only
+ DataProtectionScope.CurrentUser
+ );
+
+ return Encoding.UTF8.GetString(decryptedData);
+ } catch (Exception e) {
+ Logging.LogGenericException(e);
+ return null;
+ }
+ }
}
}
diff --git a/ConfigGenerator/BotConfig.cs b/ConfigGenerator/BotConfig.cs
index a7f4360ef..e9ae1ae59 100644
--- a/ConfigGenerator/BotConfig.cs
+++ b/ConfigGenerator/BotConfig.cs
@@ -37,7 +37,8 @@ namespace ConfigGenerator {
internal sealed class BotConfig : ASFConfig {
internal enum ECryptoMethod : byte {
PlainText,
- AES
+ AES,
+ ProtectedDataForCurrentUser
}
[JsonProperty(Required = Required.DisallowNull)]