2
2
using System . Threading ;
3
3
4
4
using Renci . SshNet . Security . Org . BouncyCastle . Crypto ;
5
+ using Renci . SshNet . Security . Org . BouncyCastle . Crypto . Digests ;
5
6
using Renci . SshNet . Security . Org . BouncyCastle . Crypto . Prng ;
6
7
using Renci . SshNet . Security . Org . BouncyCastle . Utilities ;
7
8
@@ -23,11 +24,8 @@ private static SecureRandom Master
23
24
get { return master ; }
24
25
}
25
26
26
- private static DigestRandomGenerator CreatePrng ( string digestName , bool autoSeed )
27
+ private static DigestRandomGenerator CreatePrng ( IDigest digest , bool autoSeed )
27
28
{
28
- IDigest digest = DigestUtilities . GetDigest ( digestName ) ;
29
- if ( digest == null )
30
- return null ;
31
29
DigestRandomGenerator prng = new DigestRandomGenerator ( digest ) ;
32
30
if ( autoSeed )
33
31
{
@@ -44,41 +42,10 @@ public static byte[] GetNextBytes(SecureRandom secureRandom, int length)
44
42
return result ;
45
43
}
46
44
47
- /// <summary>
48
- /// Create and auto-seed an instance based on the given algorithm.
49
- /// </summary>
50
- /// <remarks>Equivalent to GetInstance(algorithm, true)</remarks>
51
- /// <param name="algorithm">e.g. "SHA256PRNG"</param>
52
- public static SecureRandom GetInstance ( string algorithm )
53
- {
54
- return GetInstance ( algorithm , true ) ;
55
- }
56
-
57
- /// <summary>
58
- /// Create an instance based on the given algorithm, with optional auto-seeding
59
- /// </summary>
60
- /// <param name="algorithm">e.g. "SHA256PRNG"</param>
61
- /// <param name="autoSeed">If true, the instance will be auto-seeded.</param>
62
- public static SecureRandom GetInstance ( string algorithm , bool autoSeed )
63
- {
64
- string upper = algorithm . ToUpper ( ) ;
65
- if ( upper . EndsWith ( "PRNG" ) )
66
- {
67
- string digestName = upper . Substring ( 0 , upper . Length - "PRNG" . Length ) ;
68
- DigestRandomGenerator prng = CreatePrng ( digestName , autoSeed ) ;
69
- if ( prng != null )
70
- {
71
- return new SecureRandom ( prng ) ;
72
- }
73
- }
74
-
75
- throw new ArgumentException ( "Unrecognised PRNG algorithm: " + algorithm , "algorithm" ) ;
76
- }
77
-
78
45
protected readonly IRandomGenerator generator ;
79
46
80
47
public SecureRandom ( )
81
- : this ( CreatePrng ( "SHA256" , true ) )
48
+ : this ( CreatePrng ( new Sha256Digest ( ) , true ) )
82
49
{
83
50
}
84
51
0 commit comments