Replace RNGCryptoServiceProvider with RandomNumberGenerator

pull/6595/head
Bond_009 3 years ago
parent 4d1d9f23d5
commit fb2f07dc84

@ -18,7 +18,7 @@ namespace Emby.Server.Implementations.QuickConnect
/// <summary> /// <summary>
/// Quick connect implementation. /// Quick connect implementation.
/// </summary> /// </summary>
public class QuickConnectManager : IQuickConnect, IDisposable public class QuickConnectManager : IQuickConnect
{ {
/// <summary> /// <summary>
/// The length of user facing codes. /// The length of user facing codes.
@ -30,7 +30,6 @@ namespace Emby.Server.Implementations.QuickConnect
/// </summary> /// </summary>
private const int Timeout = 10; private const int Timeout = 10;
private readonly RNGCryptoServiceProvider _rng = new ();
private readonly ConcurrentDictionary<string, QuickConnectResult> _currentRequests = new (); private readonly ConcurrentDictionary<string, QuickConnectResult> _currentRequests = new ();
private readonly ConcurrentDictionary<string, (DateTime Timestamp, AuthenticationResult AuthenticationResult)> _authorizedSecrets = new (); private readonly ConcurrentDictionary<string, (DateTime Timestamp, AuthenticationResult AuthenticationResult)> _authorizedSecrets = new ();
@ -140,7 +139,7 @@ namespace Emby.Server.Implementations.QuickConnect
uint scale = uint.MaxValue; uint scale = uint.MaxValue;
while (scale == uint.MaxValue) while (scale == uint.MaxValue)
{ {
_rng.GetBytes(raw); RandomNumberGenerator.Fill(raw);
scale = BitConverter.ToUInt32(raw); scale = BitConverter.ToUInt32(raw);
} }
@ -199,31 +198,10 @@ namespace Emby.Server.Implementations.QuickConnect
return result.AuthenticationResult; return result.AuthenticationResult;
} }
/// <summary>
/// Dispose.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Dispose.
/// </summary>
/// <param name="disposing">Dispose unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_rng.Dispose();
}
}
private string GenerateSecureRandom(int length = 32) private string GenerateSecureRandom(int length = 32)
{ {
Span<byte> bytes = stackalloc byte[length]; Span<byte> bytes = stackalloc byte[length];
_rng.GetBytes(bytes); RandomNumberGenerator.Fill(bytes);
return Convert.ToHexString(bytes); return Convert.ToHexString(bytes);
} }

Loading…
Cancel
Save