Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement | Dispose RandomNumberGenerator object #1478

Merged
merged 7 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ internal static string GetSHA256Hash(byte[] input)
/// <returns>A byte array containing cryptographically generated random bytes</returns>
internal static void GenerateRandomBytes(byte[] randomBytes)
{
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
rng.GetBytes(randomBytes);
}

/// <summary>
Expand Down Expand Up @@ -367,7 +367,7 @@ internal static void VerifyColumnMasterKeySignature(string keyStoreName, string
GetListOfProviderNamesThatWereSearched(connection, command));
}

if (ShouldUseInstanceLevelProviderFlow(keyStoreName,connection, command))
if (ShouldUseInstanceLevelProviderFlow(keyStoreName, connection, command))
{
isValidSignature = provider.VerifyColumnMasterKeyMetadata(keyPath, isEnclaveEnabled, CMKSignature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ internal static byte[] GenerateRandomBytes(int length)
{
// Generate random bytes cryptographically.
byte[] randomBytes = new byte[length];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
rng.GetBytes(randomBytes);

return randomBytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ internal static byte[] GenerateRandomBytes(int length)
{
// Generate random bytes cryptographically.
byte[] randomBytes = new byte[length];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
rng.GetBytes(randomBytes);
return randomBytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public static byte[] GenerateRandomBytes(int length)
{
// Generate random bytes cryptographically.
byte[] randomBytes = new byte[length];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);

using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(randomBytes);
}

return randomBytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using Microsoft.Data.SqlClient.Server;


[Serializable]
[SqlUserDefinedType(Format.UserDefined, IsByteOrdered = false, MaxByteSize = 500)]
public class Address : INullable, IBinarySerialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,11 @@ protected virtual TDSMessageCollection CheckTDSVersion(ITDSServerSession session
private byte[] _GenerateRandomBytes(int count)
{
byte[] randomBytes = new byte[count];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(randomBytes);
}

return randomBytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ private bool ReadSecurityTokenLogin(Stream source, uint optionDataLength)
private byte[] _GenerateRandomBytes(int count)
{
byte[] randomBytes = new byte[count];
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
rng.GetBytes(randomBytes);
}

return randomBytes;
}
}
Expand Down