Skip to content

Commit 3ba8acf

Browse files
authored
Merge pull request #47 from Casido1/46-exception-thrown-when-using-the-encrypttohexstringasync
Resolved exception caused by IV key when using EncryptToHexStringAsync method for encryption
2 parents a53a904 + c2180a9 commit 3ba8acf

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/SafeCrypt.Lib/Encryption/AesEncryption/Decrypting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task<DecryptionData> DecryptFromHexStringAsync(DecryptionParameters
3838
return responseData;
3939
}
4040
// Convert input string to bytes
41-
byte[] dataBytes = param.IV.ConvertKeysToBytes();
41+
byte[] dataBytes = param.IV.HexadecimalStringToByteArray();
4242

4343
// Validate block size based on AES algorithm's requirements
4444
if (!Validators.IsValidBlockSize(dataBytes.Length))
@@ -80,7 +80,7 @@ public async Task<DecryptionData> DecryptFromBase64StringAsync(DecryptionParamet
8080
var responseData = new DecryptionData();
8181

8282
Validators.ValidateNotNull(param);
83-
83+
8484

8585
if (!Validators.IsBase64String(param.SecretKey))
8686
{

src/SafeCrypt.Lib/Encryption/AesEncryption/Encrypting.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
2-
using System.Security.Cryptography;
3-
using System.Threading.Tasks;
4-
using SafeCrypt.AesEncryption;
1+
using SafeCrypt.AesEncryption;
52
using SafeCrypt.Helpers;
63
using SafeCrypt.Models;
4+
using System;
5+
using System.Security.Cryptography;
6+
using System.Threading.Tasks;
77

88
namespace SafeCrypt.AESEncryption
99
{
@@ -35,7 +35,7 @@ public async Task<EncryptionData> EncryptToHexStringAsync(EncryptionParameters p
3535
}
3636

3737
// Convert input string to bytes
38-
byte[] dataBytes = param.IV.ConvertKeysToBytes();
38+
byte[] dataBytes = param.IV.HexadecimalStringToByteArray();
3939

4040
// Validate block size based on AES algorithm's requirements
4141
if (!Validators.IsValidBlockSize(dataBytes.Length))
@@ -139,14 +139,14 @@ private void NullChecks(string data, string secretKey)
139139
if (data == null || data.Length <= 0)
140140
throw new ArgumentNullException(nameof(data));
141141

142-
if (secretKey == null )
142+
if (secretKey == null)
143143
throw new ArgumentNullException(nameof(secretKey));
144144
}
145145

146146
private void AddError(EncryptionData responseData, string error)
147147
{
148148
responseData.HasError = true;
149149
responseData.Errors.Add(error);
150-
}
150+
}
151151
}
152152
}

src/SafeCrypt.Test/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
var decryptionData = await decryptor.DecryptFromBase64StringAsync(decryptorParam);
3333

3434
Console.WriteLine("............Decryption Started............");
35-
Console.WriteLine($"Decrypted data: { decryptionData.DecryptedData }");
35+
Console.WriteLine($"Decrypted data: {decryptionData.DecryptedData}");
3636
Console.WriteLine($"IV key: {decryptionData.Iv}");
3737
Console.WriteLine($"Secret key: {decryptionData.SecretKey}");
3838

0 commit comments

Comments
 (0)