using System;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
namespace AyaNova.Util
{


    public static class Hasher
    {


        public static string hash(string Salt, string Password)
        {

            //adapted from here:
            //https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/consumer-apis/password-hashing
            string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                       password: Password,
                       salt: Convert.FromBase64String(Salt),
                       prf: KeyDerivationPrf.HMACSHA512,
                       iterationCount: 10000,
                       numBytesRequested: 512 / 8));
            return hashed;
        }

        //Generate salt
        public static string GenerateSalt()
        {
            var salt = new byte[32];
            var random = RandomNumberGenerator.Create();
            random.GetNonZeroBytes(salt);
            return Convert.ToBase64String(salt);
        }

    }//eoc

}//eons