Tristan Warner-Smith
Tristan Warner-Smith

Reputation: 9771

What cryptographically secure options are there for creating random numbers in WinRT?

Ordinarily I'd do something like this:

byte[] randomBytes = new byte[bytes];
string randomString = Convert.ToBase64String(new RNGCryptoServiceProvider().GetBytes(randomBytes));

However there's no RNGCryptoServiceProvider available.

Are there any secure random alternatives available?

Thanks,

Upvotes: 13

Views: 1698

Answers (1)

Tristan Warner-Smith
Tristan Warner-Smith

Reputation: 9771

I managed to find an equivalent.

using Windows.Security.Cryptography;

IBuffer randomBuffer = CryptographicBuffer.GenerateRandom(PASSWORD_SALT_LENGTH);
string randomString = CryptographicBuffer.EncodeToBase64String(randomBuffer)

I hope this is of use to someone else.

Upvotes: 18

Related Questions