System.EncryptionUtils.Encrypt C# (CSharp) Method

Encrypt() public static method

Encrypts using AES (Rijndael) standard using a 256 bit key
public static Encrypt ( this data, byte key ) : byte[]
data this
key byte
return byte[]
        public static byte[] Encrypt(this byte[] data, byte[] key)
		{
			if (data == null) throw new ArgumentNullException("data");
			if (key == null || key.Length != 32) throw new ArgumentException("Key must have 32 length", "key");
			byte[] result;
            
            using (var c = Aes.Create())
			{
				c.Key = key;
				c.GenerateIV();
				using (var ms = new MemoryStream())
				{
					ms.Write(c.IV, 0, c.IV.Length);
					using (var cs = new CryptoStream(ms, c.CreateEncryptor(), CryptoStreamMode.Write))
					{
						cs.Write(data, 0, data.Length);
						cs.FlushFinalBlock();
					}
					result = ms.ToArray();
				}				
			}
			return result;
		}

Same methods

EncryptionUtils::Encrypt ( this data, string key ) : string