Skip to content

Commit 2677218

Browse files
committed
include encrypting class
1 parent c7e4f5b commit 2677218

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using SafeCrypt.src.Encrypt.AesEncryption;
2+
using SafeCrypt.src.Helpers;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Text;
6+
7+
namespace SafeCrypt.src.Encryption.AesEncryption
8+
{
9+
public class Decrypting : BaseAesEncryption
10+
{
11+
public byte[] AesDecrypt(string data, string secretKey, string iv)
12+
{
13+
NullChecks(data, secretKey, iv);
14+
15+
var (aesKey, aesIv) = ConvertKeysToBytesAndGetKeys(secretKey, iv);
16+
17+
var aesData = data.HexadecimalStringToByteArray();
18+
return DecryptAES(aesData, aesKey, aesIv);
19+
}
20+
21+
public byte[] Decrypt(byte[] data, byte[] secretKey, byte[] iv)
22+
=> DecryptAES(data, secretKey, iv);
23+
24+
25+
private void NullChecks(string data, string secretKey, string iv)
26+
{
27+
if (data == null || data.Length <= 0)
28+
throw new ArgumentNullException(nameof(data));
29+
30+
if (secretKey == null || secretKey.Length <= 0)
31+
throw new ArgumentNullException(nameof(secretKey));
32+
33+
if (iv == null || iv.Length <= 0)
34+
throw new ArgumentNullException(nameof(iv));
35+
}
36+
37+
private (byte[], byte[]) ConvertKeysToBytesAndGetKeys(string secretKey, string iv)
38+
{
39+
40+
return (secretKey.ConvertKeysToBytes(), iv.ConvertKeysToBytes());
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)