diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2020-12-30 21:16:50 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2020-12-30 21:16:50 -0600 |
| commit | 8f1068ac3135bcccf09374bc787ef22049b43461 (patch) | |
| tree | 5d80a254f5ee7b7c6b3956f6a7307591bc5a93e2 /src/slskd/Security/PBKDF2.cs | |
| parent | ec4a85e4e8b64a0ae91c494e3c8ef520f0a8b8c3 (diff) | |
| download | slskd-8f1068ac3135bcccf09374bc787ef22049b43461.tar.gz | |
copy files from example
Diffstat (limited to 'src/slskd/Security/PBKDF2.cs')
| -rw-r--r-- | src/slskd/Security/PBKDF2.cs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/slskd/Security/PBKDF2.cs b/src/slskd/Security/PBKDF2.cs new file mode 100644 index 00000000..4a857135 --- /dev/null +++ b/src/slskd/Security/PBKDF2.cs @@ -0,0 +1,28 @@ +namespace slskd.Security +{ + using Microsoft.AspNetCore.Cryptography.KeyDerivation; + using System.Security.Cryptography; + + /// <summary> + /// PBKDF2/RFC 2898 implementation + /// </summary> + public static class PBKDF2 + { + /// <summary> + /// Gets a 256 bit (32 byte) key derived from the specified <paramref name="password"/> using PBKDF2/RFC 2898 + /// </summary> + /// <param name="password"></param> + /// <returns></returns> + 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); + } + } + } +} |
