From 7f4e74af2cd9a15f6da0851bb229642c6cedc563 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 4 Apr 2024 18:44:53 +0200 Subject: [PATCH] Update MauiSettingsGeneric.cs --- src/MauiSettings/MauiSettingsGeneric.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/MauiSettings/MauiSettingsGeneric.cs b/src/MauiSettings/MauiSettingsGeneric.cs index d7e5aff..bf9d4b2 100644 --- a/src/MauiSettings/MauiSettingsGeneric.cs +++ b/src/MauiSettings/MauiSettingsGeneric.cs @@ -758,7 +758,7 @@ List settingBaseAttributes { if (settingsInfo.Value is string secureString) { - if (settingsInfo.Encrypt) + if (settingsInfo.Encrypt && !string.IsNullOrEmpty(secureString)) { if (string.IsNullOrEmpty(key)) throw new ArgumentNullException(nameof(key)); @@ -823,8 +823,10 @@ List settingBaseAttributes { if (settingsInfo.Value is string secureString) { - if (settingsInfo.Encrypt && !string.IsNullOrEmpty(key)) + if (settingsInfo.Encrypt && !string.IsNullOrEmpty(secureString)) { + if (string.IsNullOrEmpty(key)) + throw new ArgumentNullException(nameof(key)); // Encrypt string try { @@ -877,9 +879,11 @@ List settingBaseAttributes { if (settingsInfo.Value is string secureString) { - if (settingsInfo.Encrypt && !string.IsNullOrEmpty(key)) + if (settingsInfo.Encrypt && !string.IsNullOrEmpty(secureString)) { - // Decrypt string + if (string.IsNullOrEmpty(key)) + throw new ArgumentNullException(nameof(key)); + // Encrypt string try { string encryptedString = EncryptionManager.EncryptStringToBase64String(secureString, key);