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) }
                });
        }
    }
}