RNGCryptoServiceProvider Class

Implements a cryptographic Random Number Generator (RNG) using the implementation provided by the cryptographic service provider (CSP). This class cannot be inherited.

System.Object
  System.Security.Cryptography.RandomNumberGenerator
    System.Security.Cryptography.RNGCryptoServiceProvider

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

[<Sealed>]
[<ComVisibleAttribute(true)>]
type RNGCryptoServiceProvider =  
    class 
        inherit RandomNumberGenerator 
    end

The RNGCryptoServiceProvider type exposes the following members.

  NameDescription
Public methodRNGCryptoServiceProvider()Initializes a new instance of the RNGCryptoServiceProvider class.
Public methodRNGCryptoServiceProvider(Byte[])Initializes a new instance of the RNGCryptoServiceProvider class.
Public methodRNGCryptoServiceProvider(CspParameters)Initializes a new instance of the RNGCryptoServiceProvider class with the specified parameters.
Public methodRNGCryptoServiceProvider(String)Initializes a new instance of the RNGCryptoServiceProvider class.
Top

  NameDescription
Public methodDispose()When overridden in a derived class, releases all resources used by the current instance of the RandomNumberGenerator class. (Inherited from RandomNumberGenerator.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetBytesFills an array of bytes with a cryptographically strong sequence of random values. (Overrides RandomNumberGenerator.GetBytes(Byte[]).)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetNonZeroBytesFills an array of bytes with a cryptographically strong sequence of random nonzero values. (Overrides RandomNumberGenerator.GetNonZeroBytes(Byte[]).)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

Important noteImportant

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the IDisposable interface topic.

The following code example shows how to create a random number with the RNGCryptoServiceProvider class.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

This type is thread safe.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft