Skip to content

Commit d65378d

Browse files
committed
feat: add cipher mode to base aes encryption
1 parent 806b25b commit d65378d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Encryption/AesEncryption/BaseAesEncryption.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using SafeCrypt.src.Encryption.AesEncryption.Models;
1+
using SafeCrypt.Models;
22
using System;
33
using System.IO;
44
using System.Reflection;
@@ -7,7 +7,7 @@
77

88
namespace SafeCrypt.AesEncryption
99
{
10-
internal class BaseAesEncryption
10+
public class BaseAesEncryption
1111
{
1212
/// <summary>
1313
/// Encrypts the provided data using the Advanced Encryption Standard (AES) algorithm.
@@ -25,7 +25,7 @@ internal class BaseAesEncryption
2525
/// <exception cref="Exception">
2626
/// Thrown for general encryption-related exceptions.
2727
/// </exception>
28-
internal static byte[] EncryptAES(ByteEncryptionParameters param)
28+
internal static byte[] EncryptAES(ByteEncryptionParameters param, CipherMode mode = CipherMode.CBC)
2929
{
3030
try
3131
{
@@ -35,6 +35,7 @@ internal static byte[] EncryptAES(ByteEncryptionParameters param)
3535
// Set the key and initialization vector
3636
aes.Key = param.SecretKey;
3737
aes.IV = param.IV;
38+
aes.Mode = mode;
3839
// Create an encryptor using the key and initialization vector
3940
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);
4041

@@ -73,7 +74,7 @@ internal static byte[] EncryptAES(ByteEncryptionParameters param)
7374
/// <exception cref="ArgumentNullException">
7475
/// Thrown if the input encrypted data, key, or initialization vector is null.
7576
/// </exception>
76-
internal static byte[] DecryptAES(ByteDecryptionParameters param)
77+
internal static byte[] DecryptAES(ByteDecryptionParameters param, CipherMode mode = CipherMode.CBC)
7778
{
7879
try
7980
{
@@ -83,6 +84,7 @@ internal static byte[] DecryptAES(ByteDecryptionParameters param)
8384
// Set the key and initialization vector
8485
aes.Key = param.SecretKey;
8586
aes.IV = param.IV;
87+
aes.Mode= mode;
8688

8789
// Create a decryptor using the key and initialization vector
8890
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV);

0 commit comments

Comments
 (0)