Anyone knows WinRT API for Cryptographically strong Pseudo random number?
-
Thursday, April 19, 2012 4:33 AM
Hi,
What is counterpart of BCryptGenRandom()/CryptGenRandom() in WinRT C++?
Thanks,
- Edited by Mr_Jones_ Thursday, April 19, 2012 4:49 PM
All Replies
-
Friday, April 20, 2012 6:12 AM
hello, Jones:
is this what you're looking for?
UInt32 Rnd = CryptographicBuffer.GenerateRandomNumber();
I'm not familiar with crypto, so just for your referrence.
---------------------------------------------- JohnYe from SHANGHAI. email: yechzh@126.com
-
Friday, April 20, 2012 7:38 AMModerator
Please refer to CryptographicBuffer.GenerateRandom method.
Here is sample code.
using Windows.Security.Cryptography; public String GenerateRndData() { // Define the length, in bytes, of the buffer. UInt32 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 hexRnd = CryptographicBuffer.EncodeToHexString(buffer); return hexRnd; } public UInt32 GenerateRndNumber() { // Generate a random number. UInt32 Rnd = CryptographicBuffer.GenerateRandomNumber(); return Rnd; }Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Proposed As Answer by Chris Guzak Saturday, April 21, 2012 3:19 AM
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Monday, May 07, 2012 2:43 AM
-
Friday, May 25, 2012 12:40 AMHow to get actual bytes out of Ibuffer ?
-
Friday, May 25, 2012 2:01 AMModerator
You can load it into a DataReader: DataReader.FromBuffer
If you want the raw bytes you can query for its IBufferByteAccess interface--Rob
- Proposed As Answer by Rob CaplanMicrosoft Employee, Moderator Friday, May 25, 2012 2:03 AM


