public string EncryptWithIv(string dataToEncrypt, byte[] aesKey, byte[] iv)
{
var dataInBytes = new UTF8Encoding().GetBytes(dataToEncrypt);
using (var encryptor = _aesManaged.CreateEncryptor(aesKey, iv))
{
var encryptedBytes = encryptor.TransformFinalBlock(dataInBytes, 0, dataInBytes.Length);
var ivWithEncryptedBytes = new byte[iv.Length + encryptedBytes.Length];
Buffer.BlockCopy(iv, 0, ivWithEncryptedBytes, 0, iv.Length);
Buffer.BlockCopy(encryptedBytes, 0, ivWithEncryptedBytes, iv.Length, encryptedBytes.Length);
return Convert.ToBase64String(ivWithEncryptedBytes);
}
}