How to

generate cryptographically random data

Published: 8. January 2009 | Updated: 8. January 2009
License: Microsoft Public License (MS-PL)
Categories: Security
Tags: C# Security
Was this snippet helpful for you? YESYES / NONO

Import namespace

using System.Security.Cryptography;

Code

byte[] randomBytes = new byte[10];

RandomNumberGenerator generator = RNGCryptoServiceProvider.Create();
generator.GetBytes(randomBytes);
Send us feedback about this snippet »



Related Snippets: