Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Encrypt/AesEncryption/AesEncryption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public byte[] AesDecrypt(byte[] data, byte[] secretKey, byte[] iv)
public byte[] AesEncrypt(string data, string secretKey, string iv)
{
NullChecks(data, secretKey, iv);
var convertedKeys = ConvertKeysToBytes(secretKey, iv);

var aesKey = Encoding.UTF8.GetBytes(secretKey);
var aesIv = Encoding.UTF8.GetBytes(iv);
var aesData = data.HexadecimalStringToByteArray();
var aesKey = convertedKeys.Item1;
var aesIv = convertedKeys.Item2;

var aesData = data.HexadecimalStringToByteArray();
return EncryptAES(aesData, aesKey, aesIv);
}

Expand Down Expand Up @@ -81,6 +82,13 @@ private void NullChecks(string data, string secretKey, string iv)
throw new ArgumentNullException(nameof(iv));
}

private (byte[], byte[]) ConvertKeysToBytes(string secretKey, string ivKey)
{
var secret = Encoding.UTF8.GetBytes(secretKey);
var iv = Encoding.UTF8.GetBytes(ivKey);

return (secret, iv);
}
private void NullChecks(string data, string secretKey)
{
if (data == null || data.Length <= 0)
Expand Down