using System.Configuration;
using System.Security.Cryptography;
public static void Main()
var dummyKey = "bNFtS+duJn+wPjDNU2B0LLoVVhckygAZEmMxfCsDJgg=";
var key = Convert.FromBase64String(dummyKey);
RandomNumberGenerator.Create().GetBytes(iV);
var sb = new StringBuilder();
var value = sb.Append('4').Append('|').Append(DateTime.Now.ToString()).ToString();
var pipe = new byte[]{Convert.ToByte('|')};
var encryptedMemberKey = EncryptStringToBytes_Aes(value, key, iV);
var arrays = new byte[][]{iV, pipe, encryptedMemberKey};
var memberKey = new byte[arrays.Sum(a => a.Length)];
foreach (byte[] array in arrays) {
System.Buffer.BlockCopy(array, 0, memberKey, offset, array.Length);
Console.WriteLine(Convert.ToBase64String(memberKey));
public static byte[] EncryptStringToBytes_Aes(string value, byte[] Key, byte[] IV)
if (value == null || value.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
if (IV == null || IV.Length <= 0)
throw new ArgumentNullException("IV");
using (Aes aesAlg = Aes.Create())
aesAlg.Mode = CipherMode.CBC;
aesAlg.Padding = PaddingMode.PKCS7;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
using (MemoryStream msEncrypt = new MemoryStream())
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
encrypted = msEncrypt.ToArray();