Skip to content

Commit 2a56bc5

Browse files
committed
Add null check method
1 parent 0fd1ed9 commit 2a56bc5

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

Encrypt/AesEncryption/Encrypt.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
using System.IO;
1+
using System;
2+
using System.Text;
23
using System.Security.Cryptography;
34

45
namespace SafeCrypt
56
{
67
public class Encrypt : BaseAesEncryption
78
{
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+
1212

13-
public string AesEncryptByteToHex(byte[] data, byte[] key, byte[] iv)
13+
public string AesEncryptByteToHexString(byte[] data, byte[] secretKey, byte[] iv)
1414
{
15-
var cipherText = EncryptAES(data, key, iv);
15+
var cipherText = EncryptAES(data, secretKey, iv);
1616

1717
return cipherText.ByteArrayToHexString();
1818
}
19+
1920

20-
public string AesEncryptByteToBase64(byte[] data, byte[] key, byte[] iv)
21+
private void NullChecks(string data, string secretKey, string iv)
2122
{
22-
var cipherText = EncryptAES(data, key, iv);
23+
if (data == null || data.Length <= 0)
24+
throw new ArgumentNullException("plainText");
2325

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");
2531
}
2632

2733
//public byte[] AesEncrypt(byte[] data, byte[] key, byte[] iv, ReturnType returnType)

0 commit comments

Comments
 (0)