using System.Security.Cryptography; byte[] key = new byte[32]; // 256 bits using (RandomNumberGenerator rng = RandomNumberGenerator.Create())