Skip to content

Commit c092490

Browse files
committed
feat: update decryption logic to run async
1 parent 758507d commit c092490

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
using SafeCrypt.Models;
44
using System;
55
using System.Security.Cryptography;
6+
using System.Threading.Tasks;
67

78
namespace SafeCrypt.AESDecryption
89
{
910
public class AesDecryption : BaseAesEncryption
1011
{
11-
public DecryptionData DeEncryptFromHexString(DecryptionParameters param, CipherMode mode = CipherMode.CBC)
12+
/// <summary>
13+
/// Asynchronously decrypts data from a hexadecimal string using the specified decryption parameters and cipher mode.
14+
/// </summary>
15+
/// <param name="param">Decryption parameters containing secret key, IV, and data to decrypt.</param>
16+
/// <param name="mode">Cipher mode used for decryption (default is CipherMode.CBC).</param>
17+
/// <returns>
18+
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
19+
/// The task result is a <see cref="DecryptionData"/> object containing the decrypted data, IV, and secret key.
20+
/// If decryption fails, the <see cref="DecryptionData"/> object will contain error information.
21+
/// </returns>
22+
public async Task<DecryptionData> DecryptFromHexStringAsync(DecryptionParameters param, CipherMode mode = CipherMode.CBC)
1223
{
1324
var responseData = new DecryptionData();
1425

@@ -44,7 +55,7 @@ public DecryptionData DeEncryptFromHexString(DecryptionParameters param, CipherM
4455
Data = param.DataToDecrypt.HexadecimalStringToByteArray()
4556
};
4657

47-
var response = DecryptAES(byteEncryptionParameters, mode);
58+
var response = await DecryptAsync(byteEncryptionParameters, mode);
4859

4960
return new DecryptionData
5061
{
@@ -54,7 +65,17 @@ public DecryptionData DeEncryptFromHexString(DecryptionParameters param, CipherM
5465
};
5566
}
5667

57-
public DecryptionData DecryptFromBase64String(DecryptionParameters param, CipherMode mode = CipherMode.CBC)
68+
/// <summary>
69+
/// Asynchronously decrypts data from a Base64-encoded string using the specified decryption parameters and cipher mode.
70+
/// </summary>
71+
/// <param name="param">Decryption parameters containing secret key, IV, and data to decrypt.</param>
72+
/// <param name="mode">Cipher mode used for decryption (default is CipherMode.CBC).</param>
73+
/// <returns>
74+
/// A <see cref="Task{TResult}"/> representing the asynchronous operation.
75+
/// The task result is a <see cref="DecryptionData"/> object containing the decrypted data, IV, and secret key.
76+
/// If decryption fails, the <see cref="DecryptionData"/> object will contain error information.
77+
/// </returns>
78+
public async Task<DecryptionData> DecryptFromBase64StringAsync(DecryptionParameters param, CipherMode mode = CipherMode.CBC)
5879
{
5980
var responseData = new DecryptionData();
6081

@@ -82,7 +103,7 @@ public DecryptionData DecryptFromBase64String(DecryptionParameters param, Cipher
82103
Data = Convert.FromBase64String(param.DataToDecrypt)
83104
};
84105

85-
var response = DecryptAES(byteDecryptionParameters, mode);
106+
var response = await DecryptAsync(byteDecryptionParameters, mode);
86107

87108
return new DecryptionData
88109
{

0 commit comments

Comments
 (0)