11using System ;
22using System . Text ;
3- using System . Security . Cryptography ;
43using SafeCrypt . src . Helpers ;
54using SafeCrypt . src . Encryption . AesEncryption . Models ;
65
76namespace SafeCrypt . src . Encrypt . AesEncryption
87{
98 public class Encrypting : BaseAesEncryption
109 {
10+ /// <summary>
11+ /// Encrypts the provided data using the specified secret key and initialization vector (IV).
12+ /// </summary>
13+ /// <param name="data">The data to be encrypted.</param>
14+ /// <param name="secretKey">The secret key used for encryption.</param>
15+ /// <param name="iv">The initialization vector used for encryption.</param>
16+ /// <returns>The encrypted data as a byte array.</returns>
17+ /// <remarks>
18+ /// This method serves as a wrapper around the underlying AES encryption logic provided by the
19+ /// <see cref="EncryptAES"/> method. It simplifies the encryption process by exposing a more
20+ /// user-friendly interface, accepting data, secret key, and initialization vector as parameters.
21+ /// </remarks>
22+ /// <param name="data">The data to be encrypted.</param>
23+ /// <param name="secretKey">The secret key used for encryption.</param>
24+ /// <param name="iv">The initialization vector used for encryption.</param>
25+ /// <returns>The encrypted data as a byte array.</returns>
1126 public byte [ ] Encrypt ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
12- => EncryptAES ( data , secretKey , iv ) ;
27+ {
28+ // Delegate the encryption to the underlying AES encryption method
29+ return EncryptAES ( data , secretKey , iv ) ;
30+ }
1331
1432
1533 public byte [ ] Encrypt ( string data , string secretKey , string iv )
@@ -21,15 +39,14 @@ public byte[] Encrypt(string data, string secretKey, string iv)
2139
2240 var aesData = data . HexadecimalStringToByteArray ( ) ;
2341 return EncryptAES ( aesData , aesKey , aesIv ) ;
24- }
25-
26-
42+ }
2743
2844 public AesEncryptionData Encrypt ( string data , string secretKey )
2945 {
3046 NullChecks ( data , secretKey ) ;
3147
32- var aesIv = GenerateRandomBytes ( 16 ) ;
48+ // Generate a random 16-byte IV for AES in CBC mode
49+ var aesIv = GenerateRandomIVKeyAsBytes ( 16 ) ;
3350
3451 var aesKey = Encoding . UTF8 . GetBytes ( secretKey ) ;
3552 var aesData = data . HexadecimalStringToByteArray ( ) ;
0 commit comments