diff --git a/ArchiSteamFarm/Actions.cs b/ArchiSteamFarm/Actions.cs
index b839e1db4..3d5d4a024 100644
--- a/ArchiSteamFarm/Actions.cs
+++ b/ArchiSteamFarm/Actions.cs
@@ -56,6 +56,15 @@ namespace ArchiSteamFarm {
}
}
+ [PublicAPI]
+ public static string? Encrypt(ArchiCryptoHelper.ECryptoMethod cryptoMethod, string stringToEncrypt) {
+ if (!Enum.IsDefined(typeof(ArchiCryptoHelper.ECryptoMethod), cryptoMethod) || string.IsNullOrEmpty(stringToEncrypt)) {
+ throw new ArgumentNullException(nameof(cryptoMethod) + " || " + nameof(stringToEncrypt));
+ }
+
+ return ArchiCryptoHelper.Encrypt(cryptoMethod, stringToEncrypt);
+ }
+
[PublicAPI]
public static (bool Success, string Message) Exit() {
// Schedule the task after some time so user can receive response
diff --git a/ArchiSteamFarm/Commands.cs b/ArchiSteamFarm/Commands.cs
index a9761dc36..190a2fd90 100644
--- a/ArchiSteamFarm/Commands.cs
+++ b/ArchiSteamFarm/Commands.cs
@@ -166,6 +166,8 @@ namespace ArchiSteamFarm {
return await ResponseBlacklistRemove(steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false);
case "BLRM":
return ResponseBlacklistRemove(steamID, args[1]);
+ case "ENCRYPT" when args.Length > 2:
+ return ResponseEncrypt(steamID, args[1], Utilities.GetArgsAsText(message, 2));
case "FARM":
return await ResponseFarm(steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
case "INPUT" when args.Length > 3:
@@ -974,6 +976,24 @@ namespace ArchiSteamFarm {
return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
+ private static string? ResponseEncrypt(ulong steamID, string cryptoMethodText, string stringToEncrypt) {
+ if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount || string.IsNullOrEmpty(cryptoMethodText) || string.IsNullOrEmpty(stringToEncrypt)) {
+ throw new ArgumentNullException(nameof(steamID) + " || " + nameof(cryptoMethodText) + " || " + nameof(stringToEncrypt));
+ }
+
+ if (!ASF.IsOwner(steamID)) {
+ return null;
+ }
+
+ if (!Enum.TryParse(cryptoMethodText, true, out ArchiCryptoHelper.ECryptoMethod cryptoMethod)) {
+ return FormatStaticResponse(string.Format(Strings.ErrorIsInvalid, nameof(cryptoMethod)));
+ }
+
+ string? encryptedString = Actions.Encrypt(cryptoMethod, stringToEncrypt);
+
+ return FormatStaticResponse(!string.IsNullOrEmpty(encryptedString) ? string.Format(Strings.Result, encryptedString) : Strings.WarningFailed);
+ }
+
private static string? ResponseExit(ulong steamID) {
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
throw new ArgumentNullException(nameof(steamID));
diff --git a/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs b/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs
index 30117a976..16fd682a6 100644
--- a/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs
+++ b/ArchiSteamFarm/IPC/Controllers/Api/ASFController.cs
@@ -33,6 +33,27 @@ using Newtonsoft.Json.Linq;
namespace ArchiSteamFarm.IPC.Controllers.Api {
[Route("Api/ASF")]
public sealed class ASFController : ArchiController {
+ ///
+ /// Encrypts data with ASF encryption mechanisms using provided details.
+ ///
+ [Consumes("application/json")]
+ [HttpPost("Encrypt")]
+ [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.OK)]
+ [ProducesResponseType(typeof(GenericResponse), (int) HttpStatusCode.BadRequest)]
+ public ActionResult ASFEncryptPost([FromBody] ASFEncryptRequest request) {
+ if (request == null) {
+ throw new ArgumentNullException(nameof(request));
+ }
+
+ if (string.IsNullOrEmpty(request.StringToEncrypt)) {
+ return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(request.StringToEncrypt))));
+ }
+
+ string? encryptedString = Actions.Encrypt(request.CryptoMethod, request.StringToEncrypt!);
+
+ return Ok(new GenericResponse(encryptedString));
+ }
+
///
/// Fetches common info related to ASF as a whole.
///
diff --git a/ArchiSteamFarm/IPC/Requests/ASFEncryptRequest.cs b/ArchiSteamFarm/IPC/Requests/ASFEncryptRequest.cs
new file mode 100644
index 000000000..36a069c95
--- /dev/null
+++ b/ArchiSteamFarm/IPC/Requests/ASFEncryptRequest.cs
@@ -0,0 +1,46 @@
+// _ _ _ ____ _ _____
+// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
+// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
+// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
+// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
+// |
+// Copyright 2015-2020 Łukasz "JustArchi" Domeradzki
+// Contact: JustArchi@JustArchi.net
+// |
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// |
+// http://www.apache.org/licenses/LICENSE-2.0
+// |
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System.ComponentModel.DataAnnotations;
+using System.Diagnostics.CodeAnalysis;
+using Newtonsoft.Json;
+
+namespace ArchiSteamFarm.IPC.Requests {
+ [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
+ public sealed class ASFEncryptRequest {
+ ///
+ /// Encryption method used for encrypting this string.
+ ///
+ [JsonProperty(Required = Required.Always)]
+ [Required]
+ public readonly ArchiCryptoHelper.ECryptoMethod CryptoMethod;
+
+ ///
+ /// String to encrypt with provided .
+ ///
+ [JsonProperty(Required = Required.Always)]
+ [Required]
+ public readonly string? StringToEncrypt;
+
+ [JsonConstructor]
+ private ASFEncryptRequest() { }
+ }
+}
diff --git a/ArchiSteamFarm/Localization/Strings.Designer.cs b/ArchiSteamFarm/Localization/Strings.Designer.cs
index a5b2f3992..bb7bfb29f 100644
--- a/ArchiSteamFarm/Localization/Strings.Designer.cs
+++ b/ArchiSteamFarm/Localization/Strings.Designer.cs
@@ -1333,6 +1333,15 @@ namespace ArchiSteamFarm.Localization {
}
}
+ ///
+ /// Wyszukuje zlokalizowany ciąg podobny do ciągu Result: {0}.
+ ///
+ public static string Result {
+ get {
+ return ResourceManager.GetString("Result", resourceCulture);
+ }
+ }
+
///
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Starting....
///
diff --git a/ArchiSteamFarm/Localization/Strings.resx b/ArchiSteamFarm/Localization/Strings.resx
index 2a9bf1cec..5faad51b1 100644
--- a/ArchiSteamFarm/Localization/Strings.resx
+++ b/ArchiSteamFarm/Localization/Strings.resx
@@ -732,4 +732,8 @@ Process uptime: {1}
Received InvalidPassword error code {0} times in a row. Your password for this account is most likely wrong, aborting!
{0} will be replaced by maximum allowed number of failed login attempts
+
+ Result: {0}
+ {0} will be replaced by generic result of various functions that use this string
+
\ No newline at end of file