From ec9a2d9b8556be8f5f88b44e18a9fc03b4cefbd6 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 4 Feb 2021 17:59:41 -0600 Subject: move PBKDF2 --- src/slskd/Common/Cryptography/PBKDF2.cs | 26 ++++++++++++++++++++++++++ src/slskd/Security/PBKDF2.cs | 28 ---------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) create mode 100644 src/slskd/Common/Cryptography/PBKDF2.cs delete mode 100644 src/slskd/Security/PBKDF2.cs (limited to 'src') diff --git a/src/slskd/Common/Cryptography/PBKDF2.cs b/src/slskd/Common/Cryptography/PBKDF2.cs new file mode 100644 index 00000000..4b8b83e4 --- /dev/null +++ b/src/slskd/Common/Cryptography/PBKDF2.cs @@ -0,0 +1,26 @@ +namespace slskd.Security +{ + using Microsoft.AspNetCore.Cryptography.KeyDerivation; + using System.Security.Cryptography; + + /// + /// PBKDF2/RFC 2898 implementation + /// + public static class PBKDF2 + { + /// + /// Gets a 256 bit (32 byte) key derived from the specified using PBKDF2/RFC 2898 + /// + /// + /// + public static byte[] GetKey(string password) + { + 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); + } + } +} diff --git a/src/slskd/Security/PBKDF2.cs b/src/slskd/Security/PBKDF2.cs deleted file mode 100644 index 4a857135..00000000 --- a/src/slskd/Security/PBKDF2.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace slskd.Security -{ - using Microsoft.AspNetCore.Cryptography.KeyDerivation; - using System.Security.Cryptography; - - /// - /// PBKDF2/RFC 2898 implementation - /// - public static class PBKDF2 - { - /// - /// Gets a 256 bit (32 byte) key derived from the specified using PBKDF2/RFC 2898 - /// - /// - /// - public static byte[] GetKey(string password) - { - 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); - } - } - } -} -- cgit v1.2.3