diff --git a/docs/project/list-of-diagnostics.md b/docs/project/list-of-diagnostics.md index 0e3f10d2df6c3d..56aac0743803e5 100644 --- a/docs/project/list-of-diagnostics.md +++ b/docs/project/list-of-diagnostics.md @@ -114,6 +114,7 @@ The PR that reveals the implementation of the ` public HashAlgorithmName HashAlgorithm { get; } - [Obsolete(Obsoletions.Rfc2898OutdatedCtorMessage, DiagnosticId = Obsoletions.Rfc2898OutdatedCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(byte[] password, byte[] salt, int iterations) : this(password, salt, iterations, HashAlgorithmName.SHA1) { } + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(byte[] password, byte[] salt, int iterations, HashAlgorithmName hashAlgorithm) : this(password, salt, iterations, hashAlgorithm, clearPassword: false) { } - [Obsolete(Obsoletions.Rfc2898OutdatedCtorMessage, DiagnosticId = Obsoletions.Rfc2898OutdatedCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, byte[] salt) : this(password, salt, 1000) { } - [Obsolete(Obsoletions.Rfc2898OutdatedCtorMessage, DiagnosticId = Obsoletions.Rfc2898OutdatedCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, byte[] salt, int iterations) : this(password, salt, iterations, HashAlgorithmName.SHA1) { } + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, byte[] salt, int iterations, HashAlgorithmName hashAlgorithm) : this( Encoding.UTF8.GetBytes(password ?? throw new ArgumentNullException(nameof(password))), @@ -62,18 +64,19 @@ public Rfc2898DeriveBytes(string password, byte[] salt, int iterations, HashAlgo { } - [Obsolete(Obsoletions.Rfc2898OutdatedCtorMessage, DiagnosticId = Obsoletions.Rfc2898OutdatedCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, int saltSize) : this(password, saltSize, 1000) { } - [Obsolete(Obsoletions.Rfc2898OutdatedCtorMessage, DiagnosticId = Obsoletions.Rfc2898OutdatedCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, int saltSize, int iterations) : this(password, saltSize, iterations, HashAlgorithmName.SHA1) { } + [Obsolete(Obsoletions.Rfc2898DeriveBytesCtorMessage, DiagnosticId = Obsoletions.Rfc2898DeriveBytesCtorDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public Rfc2898DeriveBytes(string password, int saltSize, int iterations, HashAlgorithmName hashAlgorithm) { ArgumentOutOfRangeException.ThrowIfNegative(saltSize); diff --git a/src/libraries/System.Security.Cryptography/tests/Rfc2898OneShotTests.cs b/src/libraries/System.Security.Cryptography/tests/Rfc2898OneShotTests.cs index a5dbee9dc2259b..3a54623527d8d6 100644 --- a/src/libraries/System.Security.Cryptography/tests/Rfc2898OneShotTests.cs +++ b/src/libraries/System.Security.Cryptography/tests/Rfc2898OneShotTests.cs @@ -222,7 +222,9 @@ public static void Pbkdf2_PasswordBytes_Compare( HashAlgorithmName hashAlgorithmName = new HashAlgorithmName(hashAlgorithm); byte[] key1; +#pragma warning disable SYSLIB0060 // The constructors on Rfc2898DeriveBytes are obsolete. using (Rfc2898DeriveBytes instanceKdf = new Rfc2898DeriveBytes(password, salt, iterations, hashAlgorithmName)) +#pragma warning restore SYSLIB0060 { key1 = instanceKdf.GetBytes(length); } @@ -253,7 +255,9 @@ public static void Pbkdf2_PasswordString_Compare( HashAlgorithmName hashAlgorithmName = new HashAlgorithmName(hashAlgorithm); byte[] key1; +#pragma warning disable SYSLIB0060 // The constructors on Rfc2898DeriveBytes are obsolete. using (Rfc2898DeriveBytes instanceKdf = new Rfc2898DeriveBytes(password, salt, iterations, hashAlgorithmName)) +#pragma warning restore SYSLIB0060 { key1 = instanceKdf.GetBytes(length); } diff --git a/src/libraries/System.Security.Cryptography/tests/Rfc2898Tests.cs b/src/libraries/System.Security.Cryptography/tests/Rfc2898Tests.cs index 4342bebb14072d..e85bf8baae70a9 100644 --- a/src/libraries/System.Security.Cryptography/tests/Rfc2898Tests.cs +++ b/src/libraries/System.Security.Cryptography/tests/Rfc2898Tests.cs @@ -7,6 +7,8 @@ using Test.Cryptography; using Xunit; +#pragma warning disable SYSLIB0060 // Rfc2898DeriveBytes constructors are obsolete. + namespace System.Security.Cryptography { public class Rfc2898Tests @@ -119,9 +121,7 @@ public static void Ctor_SaltCopied() [Fact] public static void Ctor_DefaultIterations() { -#pragma warning disable SYSLIB0041 // Rfc2898DeriveBytes insecure constructor defaults using (var deriveBytes = new Rfc2898DeriveBytes(TestPassword, s_testSalt)) -#pragma warning restore SYSLIB0041 { Assert.Equal(DefaultIterationCount, deriveBytes.IterationCount); } @@ -373,13 +373,11 @@ public static void CheckHashAlgorithmValue(HashAlgorithmName hashAlgorithm) [Fact] public static void CryptDeriveKey_NotSupported() { -#pragma warning disable SYSLIB0041 // Rfc2898DeriveBytes insecure constructor defaults -#pragma warning disable SYSLIB0033 // Rfc2898DeriveBytes.CryptDeriveKey is obsolete using (var deriveBytes = new Rfc2898DeriveBytes(TestPassword, s_testSalt)) { +#pragma warning disable SYSLIB0033 // Rfc2898DeriveBytes.CryptDeriveKey is obsolete Assert.Throws(() => deriveBytes.CryptDeriveKey("RC2", "SHA1", 128, new byte[8])); #pragma warning restore SYSLIB0033 -#pragma warning restore SYSLIB0041 } }