#region Crypt /// <summary> /// Encrypt byte array /// </summary> /// <param name="input"></param> /// <param name="password"></param> /// <param name="salt"></param> /// <returns></returns> public static byte[] Encrypt(this byte[] input, string password, byte[] salt) { PasswordDeriveBytes pdb = new PasswordDeriveBytes(password,salt); MemoryStream ms = new MemoryStream(); Aes aes = new AesManaged(); aes.Key = pdb.GetBytes(aes.KeySize / 8); aes.IV = pdb.GetBytes(aes.BlockSize / 8); CryptoStream cs = new CryptoStream(ms, aes.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(input, 0, input.Length); cs.Close(); return ms.ToArray(); } /// <summary> /// Decrypt byte array /// </summary> /// <param name="input"></param> /// <param name="password"></param> /// <param name="salt"></param> /// <returns></returns> public static byte[] Decrypt(this byte[] input, string password, byte[] salt) { PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, salt); MemoryStream ms = new MemoryStream(); Aes aes = new AesManaged(); aes.Key = pdb.GetBytes(aes.KeySize / 8); aes.IV = pdb.GetBytes(aes.BlockSize / 8); CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(input, 0, input.Length); cs.Close(); return ms.ToArray(); } #endregion