aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common/Cryptography/CryptoExtensions.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2020-04-02 17:00:28 +0200
committerBond_009 <bond.009@outlook.com>2020-04-02 20:12:18 +0200
commit2be394089ea5b90873931b6c8d95be69b1d9a543 (patch)
treed7448ffde8a82a87379be95a6a8d65001f6c013a /MediaBrowser.Common/Cryptography/CryptoExtensions.cs
parent5a816f0b22cec12d193b19fcb9f21c7d085a3fbf (diff)
Enable Microsoft.CodeAnalysis.FxCopAnalyzers for Jellyfin.Common
Diffstat (limited to 'MediaBrowser.Common/Cryptography/CryptoExtensions.cs')
-rw-r--r--MediaBrowser.Common/Cryptography/CryptoExtensions.cs35
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 0000000000..157b0ed100
--- /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) }
+ });
+ }
+ }
+}