mirror of
https://github.com/AlexMacocian/SystemExtensions.git
synced 2026-07-15 22:29:28 +00:00
e6a06915cd
Codestyle fixes Setup CODEOWNERS Setup dependabot
59 lines
1.3 KiB
C#
59 lines
1.3 KiB
C#
using System.Security.Cryptography;
|
|
|
|
namespace System.Security.Rng;
|
|
|
|
public sealed class CryptoRngProvider : ICryptoRngProvider, IDisposable
|
|
{
|
|
private readonly RNGCryptoServiceProvider rngProvider;
|
|
private bool disposedValue;
|
|
|
|
public CryptoRngProvider()
|
|
{
|
|
this.rngProvider = new RNGCryptoServiceProvider();
|
|
}
|
|
public CryptoRngProvider(CspParameters cspParams)
|
|
{
|
|
this.rngProvider = new RNGCryptoServiceProvider(cspParams);
|
|
}
|
|
|
|
|
|
public void GetBytes(byte[] data)
|
|
{
|
|
this.rngProvider.GetBytes(data);
|
|
}
|
|
public void GetNonZeroBytes(byte[] data)
|
|
{
|
|
this.rngProvider.GetNonZeroBytes(data);
|
|
}
|
|
public byte[] GetBytes(int byteCount)
|
|
{
|
|
var bytes = new byte[byteCount];
|
|
this.GetBytes(bytes);
|
|
return bytes;
|
|
}
|
|
public byte[] GetNonZeroBytes(int byteCount)
|
|
{
|
|
var bytes = new byte[byteCount];
|
|
this.GetNonZeroBytes(bytes);
|
|
return bytes;
|
|
}
|
|
|
|
private void Dispose(bool disposing)
|
|
{
|
|
if (!this.disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
this.rngProvider.Dispose();
|
|
}
|
|
|
|
this.disposedValue = true;
|
|
}
|
|
}
|
|
public void Dispose()
|
|
{
|
|
this.Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|