aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-28 09:11:39 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-28 09:11:39 -0500
commit192db033cb76f129e9c71a1d82e0e71a291ad001 (patch)
tree6a952918ef6985c088acf4b6eec7f2594df0cf2c /src
parent845937dede800928f380285dad47a4c48f0ea731 (diff)
downloadslskd-192db033cb76f129e9c71a1d82e0e71a291ad001.tar.gz
allow PBKDF2 keys to have variable length
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Cryptography/Pbkdf2.cs5
1 files changed, 3 insertions, 2 deletions
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 <paramref name="password"/> using PBKDF2/RFC 2898.
/// </summary>
/// <param name="password">The password from which to derive the key.</param>
+ /// <param name="length">The desired length of the key, in bytes.</param>
/// <returns>The derived key.</returns>
- 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);
}
}
}