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

[Hotfix 4.0.1] | Update obsolete api calls in .NET 6 (#1401) #1471

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions doc/samples/AzureKeyVaultProviderExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ WITH VALUES (
private static string GetEncryptedValue(SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider)
{
byte[] plainTextColumnEncryptionKey = new byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(plainTextColumnEncryptionKey);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(plainTextColumnEncryptionKey);

byte[] encryptedColumnEncryptionKey = sqlColumnEncryptionAzureKeyVaultProvider.EncryptColumnEncryptionKey(s_akvUrl, s_algorithm, plainTextColumnEncryptionKey);
string EncryptedValue = string.Concat("0x", BitConverter.ToString(encryptedColumnEncryptionKey).Replace("-", string.Empty));
Expand Down
4 changes: 2 additions & 2 deletions doc/samples/AzureKeyVaultProviderExample_2_0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ WITH VALUES (
private static string GetEncryptedValue(SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider)
{
byte[] plainTextColumnEncryptionKey = new byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(plainTextColumnEncryptionKey);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(plainTextColumnEncryptionKey);

byte[] encryptedColumnEncryptionKey = sqlColumnEncryptionAzureKeyVaultProvider.EncryptColumnEncryptionKey(s_akvUrl, s_algorithm, plainTextColumnEncryptionKey);
string EncryptedValue = string.Concat("0x", BitConverter.ToString(encryptedColumnEncryptionKey).Replace("-", string.Empty));
Expand Down
4 changes: 2 additions & 2 deletions doc/samples/AzureKeyVaultProviderLegacyExample_2_0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ WITH VALUES (
private static string GetEncryptedValue(SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider)
{
byte[] plainTextColumnEncryptionKey = new byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(plainTextColumnEncryptionKey);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(plainTextColumnEncryptionKey);

byte[] encryptedColumnEncryptionKey = sqlColumnEncryptionAzureKeyVaultProvider.EncryptColumnEncryptionKey(s_akvUrl, s_algorithm, plainTextColumnEncryptionKey);
string EncryptedValue = string.Concat("0x", BitConverter.ToString(encryptedColumnEncryptionKey).Replace("-", string.Empty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ WITH VALUES (
private static string GetEncryptedValue(SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider)
{
byte[] plainTextColumnEncryptionKey = new byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(plainTextColumnEncryptionKey);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(plainTextColumnEncryptionKey);

byte[] encryptedColumnEncryptionKey = sqlColumnEncryptionAzureKeyVaultProvider.EncryptColumnEncryptionKey(s_akvUrl, s_algorithm, plainTextColumnEncryptionKey);
string EncryptedValue = string.Concat("0x", BitConverter.ToString(encryptedColumnEncryptionKey).Replace("-", string.Empty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ WITH VALUES (
private static string GetEncryptedValue(SqlColumnEncryptionAzureKeyVaultProvider sqlColumnEncryptionAzureKeyVaultProvider)
{
byte[] plainTextColumnEncryptionKey = new byte[32];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(plainTextColumnEncryptionKey);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(plainTextColumnEncryptionKey);

byte[] encryptedColumnEncryptionKey = sqlColumnEncryptionAzureKeyVaultProvider.EncryptColumnEncryptionKey(s_akvUrl, s_algorithm, plainTextColumnEncryptionKey);
string EncryptedValue = string.Concat("0x", BitConverter.ToString(encryptedColumnEncryptionKey).Replace("-", string.Empty));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void GetEnclaveSessionHelper(EnclaveSessionParameters enclaveSessionPa
{
if (shouldGenerateNonce)
{
using (RandomNumberGenerator rng = new RNGCryptoServiceProvider())
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
// Client decides to initiate the process of attesting the enclave and to establish a secure session with the enclave.
// To ensure that server send new attestation request instead of replaying / re-sending the old token, we will create a nonce for current attestation request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ internal static string GetSHA256Hash(byte[] input)
}

/// <summary>
/// Generates cryptographicall random bytes
/// Generates cryptographically random bytes
/// </summary>
/// <param name="randomBytes">No of cryptographically random bytes to be generated</param>
/// <returns>A byte array containing cryptographically generated random bytes</returns>
internal static void GenerateRandomBytes(byte[] randomBytes)
{
// Generate random bytes cryptographically.
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(randomBytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
}

/// <summary>
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];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(randomBytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);

return randomBytes;
}
Expand Down Expand Up @@ -348,8 +348,9 @@ internal static byte[] DecryptDataUsingAED(byte[] encryptedCellBlob, byte[] key,
return decryptedData;
}

#if NETFRAMEWORK
/// <summary>
/// Create a self-signed certificate without private key. NET461 only.
/// Create a self-signed certificate without private key.
/// </summary>
internal static X509Certificate2 CreateCertificateWithNoPrivateKey()
{
Expand All @@ -376,6 +377,7 @@ internal static X509Certificate2 CreateCertificateWithNoPrivateKey()

return certificate;
}
#endif

/// <summary>
/// Gets hex representation of byte array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void AkvStoreProviderVerifyFunctionWithInvalidSignature(bool fEnclaveEnab
Buffer.BlockCopy(cmkSignature, 0, tamperedCmkSignature, 0, tamperedCmkSignature.Length);

// Corrupt one byte at a time 10 times
RandomNumberGenerator rng = new RNGCryptoServiceProvider();
RandomNumberGenerator rng = RandomNumberGenerator.Create();
byte[] randomIndexInCipherText = new byte[1];
for (int i = 0; i < 10; i++)
{
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];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(randomBytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
return randomBytes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal static X509Certificate2 GetCertificate(string certificateName, StoreLoc
/// </summary>
internal static string GetCspPathFromCertificate(X509Certificate2 certificate)
{
if (certificate.PrivateKey is RSACryptoServiceProvider csp)
if (certificate.GetRSAPrivateKey() is RSACryptoServiceProvider csp)
{
return string.Concat(csp.CspKeyContainerInfo.ProviderName, @"/", csp.CspKeyContainerInfo.KeyContainerName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static byte[] GenerateRandomBytes(int length)
{
// Generate random bytes cryptographically.
byte[] randomBytes = new byte[length];
RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider();
rngCsp.GetBytes(randomBytes);
RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);

return randomBytes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,11 +739,8 @@ protected virtual TDSMessageCollection CheckTDSVersion(ITDSServerSession session
private byte[] _GenerateRandomBytes(int count)
{
byte[] randomBytes = new byte[count];

RNGCryptoServiceProvider gen = new RNGCryptoServiceProvider();
// Generate bytes
gen.GetBytes(randomBytes);

RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
return randomBytes;
}

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

RNGCryptoServiceProvider gen = new RNGCryptoServiceProvider();
// Generate bytes
gen.GetBytes(randomBytes);

RandomNumberGenerator rng = RandomNumberGenerator.Create();
rng.GetBytes(randomBytes);
return randomBytes;
}
}
Expand Down