diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 1ac9545c029bb..78509d235f7bc 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -76,6 +76,7 @@ The PR that reveals the implementation of the ` - $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017;SYSLIB0022 + $(NoWarn);SYSLIB0003;SYSLIB0004;SYSLIB0015;SYSLIB0017;SYSLIB0022;SYSLIB0023 diff --git a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.Windows.cs b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.Windows.cs index 08c45dee85cef..439454502655d 100644 --- a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.Windows.cs +++ b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.Windows.cs @@ -22,14 +22,10 @@ public class TestAccountImpersonator : IDisposable public TestAccountImpersonator() { string testAccountPassword; - using (RandomNumberGenerator rng = new RNGCryptoServiceProvider()) - { - var randomBytes = new byte[33]; - rng.GetBytes(randomBytes); + byte[] randomBytes = RandomNumberGenerator.GetBytes(33); - // Add special chars to ensure it satisfies password requirements. - testAccountPassword = Convert.ToBase64String(randomBytes) + "_-As@!%*(1)4#2"; - } + // Add special chars to ensure it satisfies password requirements. + testAccountPassword = Convert.ToBase64String(randomBytes) + "_-As@!%*(1)4#2"; DateTime accountExpirationDate = DateTime.UtcNow + TimeSpan.FromMinutes(2); using (var principalCtx = new PrincipalContext(ContextType.Machine)) diff --git a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs index a992ffcf0392f..b6e8614320410 100644 --- a/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs +++ b/src/libraries/System.Security.Cryptography.Csp/ref/System.Security.Cryptography.Csp.cs @@ -175,6 +175,7 @@ public RC2CryptoServiceProvider() { } public override void GenerateIV() { } public override void GenerateKey() { } } + [System.ObsoleteAttribute("RNGCryptoServiceProvider is obsolete. To generate a random number, use one of the RandomNumberGenerator static methods instead.", DiagnosticId = "SYSLIB0023", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public sealed partial class RNGCryptoServiceProvider : System.Security.Cryptography.RandomNumberGenerator { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj b/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj index da68c42443e03..2e8119ae25704 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj +++ b/src/libraries/System.Security.Cryptography.Csp/src/System.Security.Cryptography.Csp.csproj @@ -27,6 +27,8 @@ + @@ -120,3 +122,5 @@ public static void VerifyCtors() } } } + +#pragma warning restore SYSLIB0023 diff --git a/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityImpersonatedTests.netcoreapp.cs b/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityImpersonatedTests.netcoreapp.cs index 02846c7bffab7..868afcc8c1a4f 100644 --- a/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityImpersonatedTests.netcoreapp.cs +++ b/src/libraries/System.Security.Principal.Windows/tests/WindowsIdentityImpersonatedTests.netcoreapp.cs @@ -128,7 +128,7 @@ public WindowsTestAccount(string userName) private void CreateUser() { string testAccountPassword; - using (RandomNumberGenerator rng = new RNGCryptoServiceProvider()) + using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { byte[] randomBytes = new byte[33]; rng.GetBytes(randomBytes);