@@ -10,9 +10,7 @@ public class Encrypting : BaseAesEncryption
1010 /// <summary>
1111 /// Encrypts the provided data using the specified secret key and initialization vector (IV).
1212 /// </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>
13+ /// <param name="parameters">The encryption parameters.</param>
1614 /// <returns>The encrypted data as a byte array.</returns>
1715 /// <remarks>
1816 /// This method serves as a wrapper around the underlying AES encryption logic provided by the
@@ -23,62 +21,138 @@ public class Encrypting : BaseAesEncryption
2321 /// <param name="secretKey">The secret key used for encryption.</param>
2422 /// <param name="iv">The initialization vector used for encryption.</param>
2523 /// <returns>The encrypted data as a byte array.</returns>
26- public byte [ ] Encrypt ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
24+ public byte [ ] Encrypt ( ByteEncryptionParameters param )
2725 {
2826 // Delegate the encryption to the underlying AES encryption method
29- return EncryptAES ( data , secretKey , iv ) ;
27+ return EncryptAES ( param ) ;
3028 }
3129
3230
33- public byte [ ] Encrypt ( string data , string secretKey , string iv )
31+ public byte [ ] Encrypt ( StringEncryptionParameters param )
3432 {
35- NullChecks ( data , secretKey , iv ) ;
33+ NullChecks ( param . Data , param . SecretKey , param . IV ) ;
3634
37- var aesKey = secretKey . ConvertKeysToBytes ( ) ;
38- var aesIv = iv . ConvertKeysToBytes ( ) ;
35+ var byteEncryptionParameters = new ByteEncryptionParameters
36+ {
37+ SecretKey = param . SecretKey . ConvertKeysToBytes ( ) ,
38+ IV = param . IV . ConvertKeysToBytes ( ) ,
39+ Data = param . Data . HexadecimalStringToByteArray ( )
40+ } ;
3941
40- var aesData = data . HexadecimalStringToByteArray ( ) ;
41- return EncryptAES ( aesData , aesKey , aesIv ) ;
42- }
42+ return EncryptAES ( byteEncryptionParameters ) ;
43+ }
4344
44- public AesEncryptionData Encrypt ( string data , string secretKey )
45+ /// <summary>
46+ /// Encrypts the provided string data using the Advanced Encryption Standard (AES) algorithm.
47+ /// </summary>
48+ /// <param name="data">The string data to be encrypted.</param>
49+ /// <param name="secretKey">The secret key used for encryption.</param>
50+ /// <returns>An <see cref="AesEncrypted"/> object containing the encrypted data and initialization vector (IV).</returns>
51+ /// <remarks>
52+ /// This method encrypts the input string data using the specified secret key and a randomly generated initialization
53+ /// vector (IV) for AES encryption in Cipher Block Chaining (CBC) mode. The resulting encrypted data and IV are encapsulated
54+ /// in an <see cref="AesEncrypted"/> object, which is then returned.
55+ /// </remarks>
56+ /// <param name="data">The string data to be encrypted.</param>
57+ /// <param name="secretKey">The secret key used for encryption.</param>
58+ /// <returns>An <see cref="AesEncrypted"/> object containing the encrypted data and initialization vector (IV).</returns>
59+ /// <exception cref="ArgumentNullException">
60+ /// Thrown if the input data or secret key is null.
61+ /// </exception>
62+ public AesEncrypted Encrypt ( string data , string secretKey )
4563 {
4664 NullChecks ( data , secretKey ) ;
4765
4866 // Generate a random 16-byte IV for AES in CBC mode
4967 var aesIv = GenerateRandomIVKeyAsBytes ( 16 ) ;
5068
51- var aesKey = Encoding . UTF8 . GetBytes ( secretKey ) ;
52- var aesData = data . HexadecimalStringToByteArray ( ) ;
69+ //var aesKey = Encoding.UTF8.GetBytes(secretKey);
70+ //var aesData = data.HexadecimalStringToByteArray();
71+
72+ var byteEncryptionParameters = new ByteEncryptionParameters
73+ {
74+ SecretKey = Encoding . UTF8 . GetBytes ( secretKey ) ,
75+ IV = aesIv ,
76+ Data = data . HexadecimalStringToByteArray ( )
77+ } ;
5378
54- var response = EncryptAES ( aesData , aesKey , aesIv ) ;
79+ //var response = EncryptAES(aesData, aesKey, aesIv);
80+ var response = EncryptAES ( byteEncryptionParameters ) ;
5581
56- var responseData = new AesEncryptionData
82+ var responseData = new AesEncrypted
5783 {
5884 Data = response ,
5985 Iv = aesIv
6086 } ;
6187
6288 return responseData ;
6389 }
64-
65- public string EncryptByteToHexString ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
90+ /// <summary>
91+ /// Encrypts the provided byte data using the Advanced Encryption Standard (AES) algorithm
92+ /// and returns the encrypted data as a hexadecimal string.
93+ /// </summary>
94+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
95+ /// <returns>The encrypted data represented as a hexadecimal string.</returns>
96+ /// <remarks>
97+ /// This method encrypts the input byte data using the specified secret key and initialization vector (IV)
98+ /// using the AES algorithm. The resulting encrypted data is then converted to a hexadecimal string before being
99+ /// returned. The encryption parameters are encapsulated in a <see cref="ByteEncryptionParameters"/> object.
100+ /// </remarks>
101+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
102+ /// <returns>The encrypted data represented as a hexadecimal string.</returns>
103+ /// <exception cref="ArgumentNullException">
104+ /// Thrown if the input parameters or byte data is null.
105+ /// </exception>
106+ public string EncryptByteToHexString ( ByteEncryptionParameters param )
66107 {
67- var cipherText = EncryptAES ( data , secretKey , iv ) ;
108+ var cipherText = EncryptAES ( param ) ;
68109
110+ // Convert the encrypted data to a hexadecimal string
69111 return cipherText . ByteArrayToHexString ( ) ;
70112 }
71113
72- public string EncryptByteToBase64String ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
114+ /// <summary>
115+ /// Encrypts the provided byte data using the Advanced Encryption Standard (AES) algorithm
116+ /// and returns the encrypted data as a Base64-encoded string.
117+ /// </summary>
118+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
119+ /// <returns>The encrypted data represented as a Base64-encoded string.</returns>
120+ /// <remarks>
121+ /// This method encrypts the input byte data using the specified secret key and initialization vector (IV)
122+ /// using the AES algorithm. The resulting encrypted data is then converted to a Base64-encoded string before
123+ /// being returned. The encryption parameters are encapsulated in a <see cref="ByteEncryptionParameters"/> object.
124+ /// </remarks>
125+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
126+ /// <returns>The encrypted data represented as a Base64-encoded string.</returns>
127+ /// <exception cref="ArgumentNullException">
128+ /// Thrown if the input parameters or byte data is null.
129+ /// </exception>
130+ public string EncryptByteToBase64String ( ByteEncryptionParameters param )
73131 {
74- var cipherText = EncryptAES ( data , secretKey , iv ) ;
132+ var cipherText = EncryptAES ( param ) ;
75133
76134 return Convert . ToBase64String ( cipherText ) ;
77135 }
78136
79- public string EncryptByteToString ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
137+ /// <summary>
138+ /// Encrypts the provided byte data using the Advanced Encryption Standard (AES) algorithm
139+ /// and returns the encrypted data as a string using UTF-8 encoding.
140+ /// </summary>
141+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
142+ /// <returns>The encrypted data represented as a string using UTF-8 encoding.</returns>
143+ /// <remarks>
144+ /// This method encrypts the input byte data using the specified secret key and initialization vector (IV)
145+ /// using the AES algorithm. The resulting encrypted data is then converted to a string using UTF-8
146+ /// encoding before being returned. The encryption parameters are encapsulated in a <see cref="ByteEncryptionParameters"/> object.
147+ /// </remarks>
148+ /// <param name="param">The parameters containing the byte data, secret key, and initialization vector (IV).</param>
149+ /// <returns>The encrypted data represented as a string using UTF-8 encoding.</returns>
150+ /// <exception cref="ArgumentNullException">
151+ /// Thrown if the input parameters or byte data is null.
152+ /// </exception>
153+ public string EncryptByteToString ( ByteEncryptionParameters param )
80154 {
81- var cipherText = EncryptAES ( data , secretKey , iv ) ;
155+ var cipherText = EncryptAES ( param ) ;
82156
83157 return cipherText . BytesToString ( ) ;
84158 }
0 commit comments