From 192db033cb76f129e9c71a1d82e0e71a291ad001 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 28 Oct 2022 09:11:39 -0500 Subject: allow PBKDF2 keys to have variable length --- src/slskd/Common/Cryptography/Pbkdf2.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/Cryptography/Pbkdf2.cs b/src/slskd/Common/Cryptography/Pbkdf2.cs index 3c3246d6..eea5c966 100644 --- a/src/slskd/Common/Cryptography/Pbkdf2.cs +++ b/src/slskd/Common/Cryptography/Pbkdf2.cs @@ -29,15 +29,16 @@ namespace slskd.Cryptography /// Gets a 256 bit (32 byte) key derived from the specified using PBKDF2/RFC 2898. /// /// The password from which to derive the key. + /// The desired length of the key, in bytes. /// The derived key. - public static byte[] GetKey(string password) + public static byte[] GetKey(string password, int length = 32) { byte[] salt = new byte[16]; int iterations = 1000; using var rng = RandomNumberGenerator.Create(); rng.GetBytes(salt); - return KeyDerivation.Pbkdf2(password, salt, KeyDerivationPrf.HMACSHA256, iterations, 32); + return KeyDerivation.Pbkdf2(password, salt, KeyDerivationPrf.HMACSHA256, iterations, length); } } } -- cgit v1.2.3