22using System . Text ;
33using SafeCrypt . src . Helpers ;
44using SafeCrypt . src . Encryption . AesEncryption . Models ;
5+ using System . ComponentModel . DataAnnotations ;
56
67namespace SafeCrypt . src . Encrypt . AesEncryption
78{
@@ -23,14 +24,17 @@ public class Encrypting : BaseAesEncryption
2324 /// <returns>The encrypted data as a byte array.</returns>
2425 public byte [ ] Encrypt ( ByteEncryptionParameters param )
2526 {
27+ Validators . ValidateNotNull ( param ) ;
28+
2629 // Delegate the encryption to the underlying AES encryption method
2730 return EncryptAES ( param ) ;
2831 }
2932
3033
3134 public byte [ ] Encrypt ( StringEncryptionParameters param )
3235 {
33- NullChecks ( param . Data , param . SecretKey , param . IV ) ;
36+ Validators . ValidateNotNull ( param ) ;
37+
3438
3539 var byteEncryptionParameters = new ByteEncryptionParameters
3640 {
@@ -87,6 +91,7 @@ public AesEncrypted Encrypt(string data, string secretKey)
8791
8892 return responseData ;
8993 }
94+
9095 /// <summary>
9196 /// Encrypts the provided byte data using the Advanced Encryption Standard (AES) algorithm
9297 /// and returns the encrypted data as a hexadecimal string.
@@ -105,6 +110,8 @@ public AesEncrypted Encrypt(string data, string secretKey)
105110 /// </exception>
106111 public string EncryptByteToHexString ( ByteEncryptionParameters param )
107112 {
113+ Validators . ValidateNotNull ( param ) ;
114+
108115 var cipherText = EncryptAES ( param ) ;
109116
110117 // Convert the encrypted data to a hexadecimal string
@@ -129,6 +136,8 @@ public string EncryptByteToHexString(ByteEncryptionParameters param)
129136 /// </exception>
130137 public string EncryptByteToBase64String ( ByteEncryptionParameters param )
131138 {
139+ Validators . ValidateNotNull ( param ) ;
140+
132141 var cipherText = EncryptAES ( param ) ;
133142
134143 return Convert . ToBase64String ( cipherText ) ;
@@ -152,6 +161,8 @@ public string EncryptByteToBase64String(ByteEncryptionParameters param)
152161 /// </exception>
153162 public string EncryptByteToString ( ByteEncryptionParameters param )
154163 {
164+ Validators . ValidateNotNull ( param ) ;
165+
155166 var cipherText = EncryptAES ( param ) ;
156167
157168 return cipherText . BytesToString ( ) ;
@@ -163,16 +174,13 @@ public string EncryptByteToString(ByteEncryptionParameters param)
163174
164175 //}
165176
166- private void NullChecks ( string data , string secretKey , string iv = "" )
177+ private void NullChecks ( string data , string secretKey )
167178 {
168179 if ( data == null || data . Length <= 0 )
169180 throw new ArgumentNullException ( nameof ( data ) ) ;
170181
171182 if ( secretKey == null || secretKey . Length <= 0 )
172183 throw new ArgumentNullException ( nameof ( secretKey ) ) ;
173-
174- if ( iv == null || iv . Length <= 0 )
175- throw new ArgumentNullException ( nameof ( iv ) ) ;
176184 }
177185 }
178186
0 commit comments