Generate 32 bytes of random data : RandomNumberGenerator « Security « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.2D
25.Design Patterns
26.Windows
27.XML
28.XML LINQ
29.ADO.Net
30.Network
31.Directory Services
32.Security
33.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Security » RandomNumberGenerator 
32.8.1.Generate 32 bytes of random data
using System;
using System.Security.Cryptography;

class MainClass
{
    public static void Main() {
        byte[] number = new byte[32];
        
        RandomNumberGenerator rng = RandomNumberGenerator.Create();
        
        
        rng.GetBytes(number);
        
        // Display the random number.
        Console.WriteLine(BitConverter.ToString(number));

    }
}
B9-33-DA-50-FB-D0-A7-7A-6D-7C-12-A7-47-A5-FE-45-F0-E0-DC-87-AE-27-CE-C0-76-D5-85-5C-DF-7D-4A-82
32.8.RandomNumberGenerator
32.8.1.Generate 32 bytes of random data
32.8.2.Cryptographically sound random numbers
w___w__w__._j_av__a_2__s__.__co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.