From 9d04652f60f8d129bdaccd1baa78a1b02addd061 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 21 Jul 2024 11:59:01 +0300 Subject: [PATCH] Add SymmetricDecryptECB to util --- DepotDownloader/ContentDownloader.cs | 2 +- DepotDownloader/Util.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index d9191610..e9fe25aa 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -244,7 +244,7 @@ namespace DepotDownloader byte[] manifest_bytes; try { - manifest_bytes = CryptoHelper.SymmetricDecryptECB(input, appBetaPassword); + manifest_bytes = Util.SymmetricDecryptECB(input, appBetaPassword); } catch (Exception e) { diff --git a/DepotDownloader/Util.cs b/DepotDownloader/Util.cs index d249c1fc..39af1aeb 100644 --- a/DepotDownloader/Util.cs +++ b/DepotDownloader/Util.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -133,6 +134,23 @@ namespace DepotDownloader ).ToString(); } + /// + /// Decrypts using AES/ECB/PKCS7 + /// + public static byte[] SymmetricDecryptECB(byte[] input, byte[] key) + { + using var aes = Aes.Create(); + aes.BlockSize = 128; + aes.KeySize = 256; + aes.Mode = CipherMode.ECB; + aes.Padding = PaddingMode.PKCS7; + + using var aesTransform = aes.CreateDecryptor(key, null); + var output = aesTransform.TransformFinalBlock(input, 0, input.Length); + + return output; + } + public static async Task InvokeAsync(IEnumerable> taskFactories, int maxDegreeOfParallelism) { ArgumentNullException.ThrowIfNull(taskFactories);