Replace RNGCryptoServiceProvider with System.Security.Cryptography.RandomNumberGenerator
This commit is contained in:
parent
e712403dd9
commit
f19ddb30b2
1 changed files with 4 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using Anemonis.RandomOrg;
|
using Anemonis.RandomOrg;
|
||||||
using Geekbot.Core.GlobalSettings;
|
using Geekbot.Core.GlobalSettings;
|
||||||
|
|
||||||
|
@ -7,13 +6,13 @@ namespace Geekbot.Core.RandomNumberGenerator
|
||||||
{
|
{
|
||||||
public class RandomNumberGenerator : IRandomNumberGenerator
|
public class RandomNumberGenerator : IRandomNumberGenerator
|
||||||
{
|
{
|
||||||
private readonly RNGCryptoServiceProvider csp;
|
private readonly System.Security.Cryptography.RandomNumberGenerator rng;
|
||||||
private readonly bool _canUseRandomOrg;
|
private readonly bool _canUseRandomOrg;
|
||||||
private readonly RandomOrgClient _randomOrgClient;
|
private readonly RandomOrgClient _randomOrgClient;
|
||||||
|
|
||||||
public RandomNumberGenerator(IGlobalSettings globalSettings)
|
public RandomNumberGenerator(IGlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
csp = new RNGCryptoServiceProvider();
|
rng = System.Security.Cryptography.RandomNumberGenerator.Create();
|
||||||
|
|
||||||
var randomOrgApiKey = globalSettings.GetKey("RandomOrgApiKey");
|
var randomOrgApiKey = globalSettings.GetKey("RandomOrgApiKey");
|
||||||
if (!string.IsNullOrEmpty(randomOrgApiKey))
|
if (!string.IsNullOrEmpty(randomOrgApiKey))
|
||||||
|
@ -32,7 +31,7 @@ namespace Geekbot.Core.RandomNumberGenerator
|
||||||
|
|
||||||
if (minValue >= maxInclusiveValue)
|
if (minValue >= maxInclusiveValue)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("minValue must be lower than maxExclusiveValue");
|
throw new ArgumentOutOfRangeException("minValue", "must be lower than maxExclusiveValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_canUseRandomOrg)
|
if (_canUseRandomOrg)
|
||||||
|
@ -84,7 +83,7 @@ namespace Geekbot.Core.RandomNumberGenerator
|
||||||
private byte[] GenerateRandomBytes(int bytesNumber)
|
private byte[] GenerateRandomBytes(int bytesNumber)
|
||||||
{
|
{
|
||||||
var buffer = new byte[bytesNumber];
|
var buffer = new byte[bytesNumber];
|
||||||
csp.GetBytes(buffer);
|
rng.GetBytes(buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue