Secure Password Generator. This tool creates a cryptographically secure pseudorandom password from 8 to 128 bytes in length with no successive bytes. Note: This page uses client side javascript. It does not transmit any entered or calculated information. Other Password Tools. If that bothers you, you can always use SecureRandom number generator. Must be unguessable and kept confidential. Any potential leak of a secret is a security incident requiring immediate revocation of the key. The only way to generate a secret is with a secure random generator. Secrets shall never be stored in clear text format. Let’s break down the term “cryptographically secure pseudo-random number generator”. A pseudo-random number generator is a function. It gets a value called a “seed” as its input, and it outputs a “random number” and a new seed. This way, if you ca.
- Generate A Cryptographically Secure Key Generator
- Generate A Cryptographically Secure Key Lock
- Cryptographically Secure Prng
- Generate A Cryptographically Secure Key Login
Important This API is deprecated. New and existing software should start using Cryptography Next Generation APIs. Microsoft may remove this API in future releases.
The CryptGenRandom function fills a buffer with cryptographically random bytes.Syntax
Parameters
hProv
Handle of a cryptographic service provider (CSP) created by a call toCryptAcquireContext.
dwLen
Number of bytes of random data to be generated.
pbBuffer
Buffer to receive the returned data. This buffer must be at least dwLen bytes in length.
Optionally, the application can fill this buffer with data to use as an auxiliary random seed.
Return value
If the function succeeds, the return value is nonzero (TRUE).
If the function fails, the return value is zero (FALSE). For extended error information, callGetLastError.
The error codes prefaced by 'NTE' are generated by the particular CSP being used. Some possible error codes are listed in the following table.
![Generate A Cryptographically Secure Key Generate A Cryptographically Secure Key](/uploads/1/2/6/0/126040547/982147899.jpg)
Return code | Description |
---|---|
| One of the parameters specifies a handle that is not valid. |
| One of the parameters contains a value that is not valid. This is most often a pointer that is not valid. |
| The hProv parameter does not contain a valid context handle. |
| The function failed in some unexpected way. |
Remarks
The data produced by this function is cryptographically random. It is far more random than the data generated by the typical random number generator such as the one shipped with your C compiler.
This function is often used to generate random initialization vectors and salt values.
Software random number generators work in fundamentally the same way. They start with a random number, known as the seed, and then use an algorithm to generate a pseudo-random sequence of bits based on it. The most difficult part of this process is to get a seed that is truly random. This is usually based on user input latency, or the jitter from one or more hardware components.
With Microsoft CSPs, CryptGenRandom uses the same random number generator used by other security components. This allows numerous processes to contribute to a system-wide seed. CryptoAPI stores an intermediate random seed with every user. To form the seed for the random number generator, a calling application supplies bits it might have—for instance, mouse or keyboard timing input—that are then combined with both the stored seed and various system data and user data such as the process ID and thread ID, the system clock, the system time, the system counter, memory status, free disk clusters, the hashed user environment block. This result is used to seed the pseudorandom number generator (PRNG). In Windows Vista with Service Pack 1 (SP1) and later, an implementation of the AES counter-mode based PRNG specified in NIST Special Publication 800-90 is used. In Windows Vista, Windows Storage Server 2003, and Windows XP, the PRNG specified in Federal Information Processing Standard (FIPS) 186-2 is used. If an application has access to a good random source, it can fill the pbBuffer buffer with some random data before calling CryptGenRandom. The CSP then uses this data to further randomize its internal seed. It is acceptable to omit the step of initializing the pbBuffer buffer before calling CryptGenRandom.
Examples
The following example shows the generation of 8 random bytes. These can be used to create cryptographic keys or for any application that uses random numbers. For an example that includes the complete context for this example, see Example C Program: Duplicating a Session Key.
Requirements
Minimum supported client | Windows XP [desktop apps only] |
Minimum supported server | Windows Server 2003 [desktop apps only] |
Target Platform | Windows |
Header | wincrypt.h |
Library | Advapi32.lib |
DLL | Advapi32.dll |
See also
-->Definition
Represents the abstract class from which all implementations of cryptographic random number generators derive.
RandomNumberGenerator
![Cryptographically Cryptographically](/uploads/1/2/6/0/126040547/666615743.png)
- Derived
- Attributes
- Implements
Remarks
Cryptographic random number generators create cryptographically strong random values.
To create a random number generator, call the Create() method. This is preferred over calling the constructor of the derived class RNGCryptoServiceProvider, which is not available on all platforms.
Constructors
Generate A Cryptographically Secure Key Generator
RandomNumberGenerator() | Initializes a new instance of RandomNumberGenerator. |
Generate A Cryptographically Secure Key Lock
Methods
Create() | Creates an instance of the default implementation of a cryptographic random number generator that can be used to generate random data. |
Create(String) | Creates an instance of the specified implementation of a cryptographic random number generator. |
Dispose() | When overridden in a derived class, releases all resources used by the current instance of the RandomNumberGenerator class. |
Dispose(Boolean) | When overridden in a derived class, releases the unmanaged resources used by the RandomNumberGenerator and optionally releases the managed resources. |
Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Fill(Span<Byte>) | Fills a span with cryptographically strong random bytes. |
GetBytes(Byte[]) | When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values. |
GetBytes(Byte[], Int32, Int32) | Fills the specified byte array with a cryptographically strong random sequence of values. |
GetBytes(Span<Byte>) | Fills a span with cryptographically strong random bytes. |
GetHashCode() | Serves as the default hash function. (Inherited from Object) |
GetInt32(Int32) | Generates a random integer between 0 (inclusive) and a specified exclusive upper bound using a cryptographically strong random number generator. |
GetInt32(Int32, Int32) | Generates a random integer between a specified inclusive lower bound and a specified exclusive upper bound using a cryptographically strong random number generator. |
GetNonZeroBytes(Byte[]) | When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of nonzero values. |
GetNonZeroBytes(Span<Byte>) | Fills a byte span with a cryptographically strong random sequence of nonzero values. |
GetType() | Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object) |
ToString() | Returns a string that represents the current object. (Inherited from Object) |