diff options
| author | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-04-06 00:24:11 -0400 |
|---|---|---|
| committer | Mark Monteiro <marknr.monteiro@protonmail.com> | 2020-04-06 00:24:11 -0400 |
| commit | 5bc6c08a0aead61ef8e7566916fbe36a4dc5bd3d (patch) | |
| tree | c44cadafa32e7edf6cff5aae09601e0e2e289a8e /MediaBrowser.Common/Cryptography/CryptoExtensions.cs | |
| parent | 410a322fe22302eb3c8a37ea38bbe1d7e9d12aff (diff) | |
| parent | 92af81166d00eb886e1111c4b7dc9788cacc619a (diff) | |
Merge remote-tracking branch 'upstream/master' into simplify-https-config
Diffstat (limited to 'MediaBrowser.Common/Cryptography/CryptoExtensions.cs')
| -rw-r--r-- | MediaBrowser.Common/Cryptography/CryptoExtensions.cs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Cryptography/CryptoExtensions.cs b/MediaBrowser.Common/Cryptography/CryptoExtensions.cs new file mode 100644 index 000000000..157b0ed10 --- /dev/null +++ b/MediaBrowser.Common/Cryptography/CryptoExtensions.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Globalization; +using System.Text; +using MediaBrowser.Model.Cryptography; +using static MediaBrowser.Common.Cryptography.Constants; + +namespace MediaBrowser.Common.Cryptography +{ + /// <summary> + /// Class containing extension methods for working with Jellyfin cryptography objects. + /// </summary> + public static class CryptoExtensions + { + /// <summary> + /// Creates a new <see cref="PasswordHash" /> instance. + /// </summary> + /// <param name="cryptoProvider">The <see cref="ICryptoProvider" /> instance used.</param> + /// <param name="password">The password that will be hashed.</param> + /// <returns>A <see cref="PasswordHash" /> instance with the hash method, hash, salt and number of iterations.</returns> + public static PasswordHash CreatePasswordHash(this ICryptoProvider cryptoProvider, string password) + { + byte[] salt = cryptoProvider.GenerateSalt(); + return new PasswordHash( + cryptoProvider.DefaultHashMethod, + cryptoProvider.ComputeHashWithDefaultMethod( + Encoding.UTF8.GetBytes(password), + salt), + salt, + new Dictionary<string, string> + { + { "iterations", DefaultIterations.ToString(CultureInfo.InvariantCulture) } + }); + } + } +} |
