aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Cryptography/Extensions.cs
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-10-28 21:54:40 -0700
committerGitHub <noreply@github.com>2019-10-28 21:54:40 -0700
commit8edb1c49d8d1835566bd30d8bf5460ab707b1ede (patch)
tree03c6b38523efcc4f29691cea3cdc4def0e8d26d8 /MediaBrowser.Common/Cryptography/Extensions.cs
parent984e415c66cbd995d12ea95a3a9d3e2561ce4869 (diff)
parentc9f4a74af02e08b895cd6a8b8a408b1c0edfb6c4 (diff)
Merge pull request #6 from jellyfin/master
Bringing my branch up to sync
Diffstat (limited to 'MediaBrowser.Common/Cryptography/Extensions.cs')
-rw-r--r--MediaBrowser.Common/Cryptography/Extensions.cs35
1 files changed, 35 insertions, 0 deletions
diff --git a/MediaBrowser.Common/Cryptography/Extensions.cs b/MediaBrowser.Common/Cryptography/Extensions.cs
new file mode 100644
index 000000000..1e32a6d1a
--- /dev/null
+++ b/MediaBrowser.Common/Cryptography/Extensions.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 Extensions
+ {
+ /// <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) }
+ });
+ }
+ }
+}