From 2be394089ea5b90873931b6c8d95be69b1d9a543 Mon Sep 17 00:00:00 2001 From: Bond_009 Date: Thu, 2 Apr 2020 17:00:28 +0200 Subject: Enable Microsoft.CodeAnalysis.FxCopAnalyzers for Jellyfin.Common --- .../Cryptography/CryptoExtensions.cs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 MediaBrowser.Common/Cryptography/CryptoExtensions.cs (limited to 'MediaBrowser.Common/Cryptography/CryptoExtensions.cs') 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 +{ + /// + /// Class containing extension methods for working with Jellyfin cryptography objects. + /// + public static class CryptoExtensions + { + /// + /// Creates a new instance. + /// + /// The instance used. + /// The password that will be hashed. + /// A instance with the hash method, hash, salt and number of iterations. + 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 + { + { "iterations", DefaultIterations.ToString(CultureInfo.InvariantCulture) } + }); + } + } +} -- cgit v1.2.3