From d0f23a2cffbbf9864f41739cc6dec21c19f87a4a Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Tue, 30 Mar 2021 16:33:15 -0400 Subject: [PATCH] Clean up NetCore PBKDF2 provider. (#31391) --- .../src/PBKDF2/NetCorePbkdf2Provider.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs index 35d130c2ad5d..8baefe0329e5 100644 --- a/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs +++ b/src/DataProtection/Cryptography.KeyDerivation/src/PBKDF2/NetCorePbkdf2Provider.cs @@ -14,8 +14,6 @@ namespace Microsoft.AspNetCore.Cryptography.KeyDerivation.PBKDF2 /// internal sealed class NetCorePbkdf2Provider : IPbkdf2Provider { - private static readonly ManagedPbkdf2Provider _fallbackProvider = new ManagedPbkdf2Provider(); - public byte[] DeriveKey(string password, byte[] salt, KeyDerivationPrf prf, int iterationCount, int numBytesRequested) { Debug.Assert(password != null); @@ -23,21 +21,6 @@ public byte[] DeriveKey(string password, byte[] salt, KeyDerivationPrf prf, int Debug.Assert(iterationCount > 0); Debug.Assert(numBytesRequested > 0); - if (salt.Length < 8) - { - // Rfc2898DeriveBytes enforces the 8 byte recommendation. - // To maintain compatibility, we call into ManagedPbkdf2Provider for salts shorter than 8 bytes - // because we can't use Rfc2898DeriveBytes with this salt. - return _fallbackProvider.DeriveKey(password, salt, prf, iterationCount, numBytesRequested); - } - else - { - return DeriveKeyImpl(password, salt, prf, iterationCount, numBytesRequested); - } - } - - private static byte[] DeriveKeyImpl(string password, byte[] salt, KeyDerivationPrf prf, int iterationCount, int numBytesRequested) - { HashAlgorithmName algorithmName; switch (prf) { @@ -54,7 +37,7 @@ private static byte[] DeriveKeyImpl(string password, byte[] salt, KeyDerivationP throw new ArgumentOutOfRangeException(); } - return Rfc2898DeriveBytes.Pbkdf2(Encoding.UTF8.GetBytes(password), salt, iterationCount, algorithmName, numBytesRequested); + return Rfc2898DeriveBytes.Pbkdf2(password, salt, iterationCount, algorithmName, numBytesRequested); } } }