From c2180a93c7e4866ca44a7885b650f828d6cdaadc Mon Sep 17 00:00:00 2001 From: Casido1 Date: Sun, 11 Feb 2024 11:33:58 +0100 Subject: [PATCH] Resolved exception --- .../Encryption/AesEncryption/Decrypting.cs | 4 ++-- .../Encryption/AesEncryption/Encrypting.cs | 14 +++++++------- src/SafeCrypt.Test/Program.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/SafeCrypt.Lib/Encryption/AesEncryption/Decrypting.cs b/src/SafeCrypt.Lib/Encryption/AesEncryption/Decrypting.cs index ae42d21..62cf941 100644 --- a/src/SafeCrypt.Lib/Encryption/AesEncryption/Decrypting.cs +++ b/src/SafeCrypt.Lib/Encryption/AesEncryption/Decrypting.cs @@ -38,7 +38,7 @@ public async Task DecryptFromHexStringAsync(DecryptionParameters return responseData; } // Convert input string to bytes - byte[] dataBytes = param.IV.ConvertKeysToBytes(); + byte[] dataBytes = param.IV.HexadecimalStringToByteArray(); // Validate block size based on AES algorithm's requirements if (!Validators.IsValidBlockSize(dataBytes.Length)) @@ -80,7 +80,7 @@ public async Task DecryptFromBase64StringAsync(DecryptionParamet var responseData = new DecryptionData(); Validators.ValidateNotNull(param); - + if (!Validators.IsBase64String(param.SecretKey)) { diff --git a/src/SafeCrypt.Lib/Encryption/AesEncryption/Encrypting.cs b/src/SafeCrypt.Lib/Encryption/AesEncryption/Encrypting.cs index ca76d78..75fa8ae 100644 --- a/src/SafeCrypt.Lib/Encryption/AesEncryption/Encrypting.cs +++ b/src/SafeCrypt.Lib/Encryption/AesEncryption/Encrypting.cs @@ -1,9 +1,9 @@ -using System; -using System.Security.Cryptography; -using System.Threading.Tasks; -using SafeCrypt.AesEncryption; +using SafeCrypt.AesEncryption; using SafeCrypt.Helpers; using SafeCrypt.Models; +using System; +using System.Security.Cryptography; +using System.Threading.Tasks; namespace SafeCrypt.AESEncryption { @@ -35,7 +35,7 @@ public async Task EncryptToHexStringAsync(EncryptionParameters p } // Convert input string to bytes - byte[] dataBytes = param.IV.ConvertKeysToBytes(); + byte[] dataBytes = param.IV.HexadecimalStringToByteArray(); // Validate block size based on AES algorithm's requirements if (!Validators.IsValidBlockSize(dataBytes.Length)) @@ -139,7 +139,7 @@ private void NullChecks(string data, string secretKey) if (data == null || data.Length <= 0) throw new ArgumentNullException(nameof(data)); - if (secretKey == null ) + if (secretKey == null) throw new ArgumentNullException(nameof(secretKey)); } @@ -147,6 +147,6 @@ private void AddError(EncryptionData responseData, string error) { responseData.HasError = true; responseData.Errors.Add(error); - } + } } } diff --git a/src/SafeCrypt.Test/Program.cs b/src/SafeCrypt.Test/Program.cs index 79b733e..812e804 100644 --- a/src/SafeCrypt.Test/Program.cs +++ b/src/SafeCrypt.Test/Program.cs @@ -32,7 +32,7 @@ var decryptionData = await decryptor.DecryptFromBase64StringAsync(decryptorParam); Console.WriteLine("............Decryption Started............"); -Console.WriteLine($"Decrypted data: { decryptionData.DecryptedData }"); +Console.WriteLine($"Decrypted data: {decryptionData.DecryptedData}"); Console.WriteLine($"IV key: {decryptionData.Iv}"); Console.WriteLine($"Secret key: {decryptionData.SecretKey}");