Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This example code shows how to create a random number or buffer for use in cryptography in a WinUI app.
public string GenerateRandomData()
{
// Define the length, in bytes, of the buffer.
uint length = 32;
// Generate random data and copy it to a buffer.
IBuffer buffer = CryptographicBuffer.GenerateRandom(length);
// Encode the buffer to a hexadecimal string (for display).
string randomHex = CryptographicBuffer.EncodeToHexString(buffer);
return randomHex;
}
public uint GenerateRandomNumber()
{
// Generate a random number.
uint random = CryptographicBuffer.GenerateRandomNumber();
return random;
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Windows developer