Example dotnet core console project that encrypts and decrypts data.

using System;
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace EncryptDecryptData
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            var key = Guid.NewGuid().ToString("N");
            const string valueToEncrypt = "Hello World!";
            
            var encrypted = Encrypt(valueToEncrypt, key);
            var decrypted = Decrypt(encrypted, key);

            Console.WriteLine(valueToEncrypt);
            Console.WriteLine(encrypted);
            Console.WriteLine(decrypted);

            Console.ReadKey();
        }

        private static string Encrypt(string text, string key)
        {
            var keybytes = Encoding.UTF8.GetBytes(key);

            using (var aes = Aes.Create())
            {
                Debug.Assert(aes != null, nameof(aes) + " != null");
                
                using (var encryptor = aes.CreateEncryptor(keybytes, aes.IV))
                {
                    using (var ms = new MemoryStream())
                    {
                        using (var cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write))
                        {
                            using (var sw = new StreamWriter(cs))
                            {
                                sw.Write(text);
                            }
                        }

                        var iv = aes.IV;
                        var encrypted = ms.ToArray();
                        var result = new byte[iv.Length + encrypted.Length];

                        Buffer.BlockCopy(iv, 0, result, 0, iv.Length);
                        Buffer.BlockCopy(encrypted, 0, result, iv.Length, encrypted.Length);

                        return Convert.ToBase64String(result);
                    }
                }
            }
        }

        private static string Decrypt(string encrypted, string key)
        {
            var encryptedBytes = Convert.FromBase64String(encrypted);

            var iv = new byte[16];
            var cipher = new byte[16];

            Buffer.BlockCopy(encryptedBytes, 0, iv, 0, iv.Length);
            Buffer.BlockCopy(encryptedBytes, iv.Length, cipher, 0, iv.Length);

            var keybytes = Encoding.UTF8.GetBytes(key);

            using (var aes = Aes.Create())
            {
                Debug.Assert(aes != null, nameof(aes) + " != null");
                
                using (var decryptor = aes.CreateDecryptor(keybytes, iv))
                {
                    string result;
                    using (var ms = new MemoryStream(cipher))
                    {
                        using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
                        {
                            using (var sr = new StreamReader(cs))
                            {
                                result = sr.ReadToEnd();
                            }
                        }
                    }

                    return result;
                }
            }
        }
    }
}