Skip to content

Commit a6a8cc9

Browse files
authored
Merge pull request #10 from selfmadecode/dev_raphael_aes
merge raphael aes into dev
2 parents 1fab22a + 6bd0028 commit a6a8cc9

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Encrypt/AesEncryption/AesEncryption.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ public byte[] AesDecrypt(byte[] data, byte[] secretKey, byte[] iv)
1515
public byte[] AesEncrypt(string data, string secretKey, string iv)
1616
{
1717
NullChecks(data, secretKey, iv);
18+
var convertedKeys = ConvertKeysToBytes(secretKey, iv);
1819

19-
var aesKey = Encoding.UTF8.GetBytes(secretKey);
20-
var aesIv = Encoding.UTF8.GetBytes(iv);
21-
var aesData = data.HexadecimalStringToByteArray();
20+
var aesKey = convertedKeys.Item1;
21+
var aesIv = convertedKeys.Item2;
2222

23+
var aesData = data.HexadecimalStringToByteArray();
2324
return EncryptAES(aesData, aesKey, aesIv);
2425
}
2526

@@ -81,6 +82,13 @@ private void NullChecks(string data, string secretKey, string iv)
8182
throw new ArgumentNullException(nameof(iv));
8283
}
8384

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+
}
8492
private void NullChecks(string data, string secretKey)
8593
{
8694
if (data == null || data.Length <= 0)

0 commit comments

Comments
 (0)