44
55namespace SafeCrypt
66{
7- public class Encrypt : BaseAesEncryption
7+ public class AesEncryption : BaseAesEncryption
88 {
99 public byte [ ] AesEncrypt ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
1010 => EncryptAES ( data , secretKey , iv ) ;
1111
12+ public byte [ ] AesDecrypt ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
13+ => DecryptAES ( data , secretKey , iv ) ;
14+
1215 public byte [ ] AesEncrypt ( string data , string secretKey , string iv )
1316 {
1417 NullChecks ( data , secretKey , iv ) ;
18+ var convertedKeys = ConvertKeysToBytes ( secretKey , iv ) ;
1519
16- var aesKey = Encoding . UTF8 . GetBytes ( secretKey ) ;
17- var aesIv = Encoding . UTF8 . GetBytes ( iv ) ;
18- var aesData = data . HexadecimalStringToByteArray ( ) ;
20+ var aesKey = convertedKeys . Item1 ;
21+ var aesIv = convertedKeys . Item2 ;
1922
23+ var aesData = data . HexadecimalStringToByteArray ( ) ;
2024 return EncryptAES ( aesData , aesKey , aesIv ) ;
2125 }
2226
23- public AesData AesEncrypt ( string data , string secretKey )
27+ public AesEncryptionData AesEncrypt ( string data , string secretKey )
2428 {
2529 NullChecks ( data , secretKey ) ;
2630
@@ -30,7 +34,7 @@ public AesData AesEncrypt(string data, string secretKey)
3034
3135 var response = EncryptAES ( aesData , aesKey , aesIv ) ;
3236
33- var responseData = new AesData
37+ var responseData = new AesEncryptionData
3438 {
3539 Data = response ,
3640 Iv = aesIv
@@ -60,34 +64,42 @@ public string AesEncryptByteToString(byte[] data, byte[] secretKey, byte[] iv)
6064 return cipherText . BytesToString ( ) ;
6165 }
6266
67+ // needs methods that would accept aes mode
68+ //public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv, ReturnType returnType)
69+ //{
70+
71+ //}
72+
6373 private void NullChecks ( string data , string secretKey , string iv )
6474 {
6575 if ( data == null || data . Length <= 0 )
66- throw new ArgumentNullException ( "plainText" ) ;
76+ throw new ArgumentNullException ( nameof ( data ) ) ;
6777
6878 if ( secretKey == null || secretKey . Length <= 0 )
69- throw new ArgumentNullException ( "Key" ) ;
79+ throw new ArgumentNullException ( nameof ( secretKey ) ) ;
7080
7181 if ( iv == null || iv . Length <= 0 )
72- throw new ArgumentNullException ( "IV" ) ;
82+ throw new ArgumentNullException ( nameof ( iv ) ) ;
7383 }
7484
85+ private ( byte [ ] , byte [ ] ) ConvertKeysToBytes ( string secretKey , string ivKey )
86+ {
87+ var secret = Encoding . UTF8 . GetBytes ( secretKey ) ;
88+ var iv = Encoding . UTF8 . GetBytes ( ivKey ) ;
89+
90+ return ( secret , iv ) ;
91+ }
7592 private void NullChecks ( string data , string secretKey )
7693 {
7794 if ( data == null || data . Length <= 0 )
78- throw new ArgumentNullException ( "plainText" ) ;
95+ throw new ArgumentNullException ( nameof ( data ) ) ;
7996
8097 if ( secretKey == null || secretKey . Length <= 0 )
81- throw new ArgumentNullException ( "Key" ) ;
82- }
83-
84- //public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv, ReturnType returnType)
85- //{
86-
87- //}
98+ throw new ArgumentNullException ( nameof ( secretKey ) ) ;
99+ }
88100 }
89101
90- public class AesData
102+ public class AesEncryptionData
91103 {
92104 public byte [ ] Data { get ; set ; }
93105 public byte [ ] Iv { get ; set ; }
0 commit comments