From 6adab25facbcaa8a93c6d243b7933d034f1ac147 Mon Sep 17 00:00:00 2001 From: CasualPokePlayer <50538166+CasualPokePlayer@users.noreply.github.com> Date: Fri, 10 Jan 2025 08:30:11 -0800 Subject: [PATCH] Make EncryptString/DecryptString arguments be nullable and properly check for null/empty --- src/BizHawk.Common/SecretStrings.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BizHawk.Common/SecretStrings.cs b/src/BizHawk.Common/SecretStrings.cs index a9514c819c..b39edd7f79 100644 --- a/src/BizHawk.Common/SecretStrings.cs +++ b/src/BizHawk.Common/SecretStrings.cs @@ -61,8 +61,13 @@ namespace BizHawk.Common _aes.Padding = PaddingMode.PKCS7; } - public static string EncryptString(string secretString) + public static string EncryptString(string? secretString) { + if (string.IsNullOrEmpty(secretString)) + { + return string.Empty; + } + var bytes = Encoding.UTF8.GetBytes(secretString); using var ms = new MemoryStream(); using var encryptor = _aes.CreateEncryptor(); @@ -74,7 +79,7 @@ namespace BizHawk.Common return Convert.ToBase64String(ms.ToArray()); } - public static string DecryptString(string encryptedString) + public static string DecryptString(string? encryptedString) { try {