CryptoApiRandomGenerator
using System;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security.Cryptography;
using Windows.Security.Cryptography;
namespace Renci.SshNet.Security.Org.BouncyCastle.Crypto.Prng
{
internal class CryptoApiRandomGenerator : IRandomGenerator
{
private readonly RandomNumberGenerator rndProv;
public CryptoApiRandomGenerator()
{
}
public CryptoApiRandomGenerator(RandomNumberGenerator rng)
{
rndProv = rng;
}
public virtual void AddSeedMaterial(byte[] seed)
{
}
public virtual void AddSeedMaterial(long seed)
{
}
public virtual void NextBytes(byte[] bytes)
{
if (bytes == null)
throw new ArgumentNullException("bytes");
WindowsRuntimeBufferExtensions.CopyTo(CryptographicBuffer.GenerateRandom((uint)bytes.Length), bytes);
}
public virtual void NextBytes(byte[] bytes, int start, int len)
{
if (start < 0)
throw new ArgumentException("Start offset cannot be negative", "start");
if (bytes.Length < start + len)
throw new ArgumentException("Byte array too small for requested offset and length");
if (bytes.Length == len && start == 0)
NextBytes(bytes);
else {
byte[] array = new byte[len];
NextBytes(array);
Array.Copy(array, 0, bytes, start, len);
}
}
}
}