|
1 | | -using System.IO; |
| 1 | +using System; |
| 2 | +using System.Text; |
2 | 3 | using System.Security.Cryptography; |
3 | 4 |
|
4 | 5 | namespace SafeCrypt |
5 | 6 | { |
6 | 7 | public class Encrypt : BaseAesEncryption |
7 | 8 | { |
8 | | - public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv) |
9 | | - { |
10 | | - return EncryptAES(data, key, iv); |
11 | | - } |
| 9 | + public byte[] AesEncrypt(byte[] data, byte[] secretKey, byte[] iv) |
| 10 | + => EncryptAES(data, secretKey, iv); |
| 11 | + |
12 | 12 |
|
13 | | - public string AesEncryptByteToHex(byte[] data, byte[] key, byte[] iv) |
| 13 | + public string AesEncryptByteToHexString(byte[] data, byte[] secretKey, byte[] iv) |
14 | 14 | { |
15 | | - var cipherText = EncryptAES(data, key, iv); |
| 15 | + var cipherText = EncryptAES(data, secretKey, iv); |
16 | 16 |
|
17 | 17 | return cipherText.ByteArrayToHexString(); |
18 | 18 | } |
| 19 | + |
19 | 20 |
|
20 | | - public string AesEncryptByteToBase64(byte[] data, byte[] key, byte[] iv) |
| 21 | + private void NullChecks(string data, string secretKey, string iv) |
21 | 22 | { |
22 | | - var cipherText = EncryptAES(data, key, iv); |
| 23 | + if (data == null || data.Length <= 0) |
| 24 | + throw new ArgumentNullException("plainText"); |
23 | 25 |
|
24 | | - return cipherText.ByteArrayToHexString(); |
| 26 | + if (secretKey == null || secretKey.Length <= 0) |
| 27 | + throw new ArgumentNullException("Key"); |
| 28 | + |
| 29 | + if (iv == null || iv.Length <= 0) |
| 30 | + throw new ArgumentNullException("IV"); |
25 | 31 | } |
26 | 32 |
|
27 | 33 | //public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv, ReturnType returnType) |
|
0 commit comments