@@ -20,6 +20,25 @@ public byte[] AesEncrypt(string data, string secretKey, string iv)
2020 return EncryptAES ( aesData , aesKey , aesIv ) ;
2121 }
2222
23+ public AesData AesEncrypt ( string data , string secretKey )
24+ {
25+ NullChecks ( data , secretKey ) ;
26+
27+ var aesIv = GenerateRandomBytes ( 16 ) ;
28+ var aesKey = Encoding . UTF8 . GetBytes ( secretKey ) ;
29+ var aesData = data . HexadecimalStringToByteArray ( ) ;
30+
31+ var response = EncryptAES ( aesData , aesKey , aesIv ) ;
32+
33+ var responseData = new AesData
34+ {
35+ Data = response ,
36+ Iv = aesIv
37+ } ;
38+
39+ return responseData ;
40+ }
41+
2342 public string AesEncryptByteToHexString ( byte [ ] data , byte [ ] secretKey , byte [ ] iv )
2443 {
2544 var cipherText = EncryptAES ( data , secretKey , iv ) ;
@@ -53,9 +72,24 @@ private void NullChecks(string data, string secretKey, string iv)
5372 throw new ArgumentNullException ( "IV" ) ;
5473 }
5574
75+ private void NullChecks ( string data , string secretKey )
76+ {
77+ if ( data == null || data . Length <= 0 )
78+ throw new ArgumentNullException ( "plainText" ) ;
79+
80+ if ( secretKey == null || secretKey . Length <= 0 )
81+ throw new ArgumentNullException ( "Key" ) ;
82+ }
83+
5684 //public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv, ReturnType returnType)
5785 //{
5886
5987 //}
6088 }
89+
90+ public class AesData
91+ {
92+ public byte [ ] Data { get ; set ; }
93+ public byte [ ] Iv { get ; set ; }
94+ }
6195}
0 commit comments