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); } // /// // /// Generate a random ID // /// // /// HEX // internal static string GenerateStrongId() // { // var s = new byte[32]; // var random = RandomNumberGenerator.Create(); // random.GetNonZeroBytes(s); // return BitConverter.ToString(s).Replace("-", string.Empty).ToLowerInvariant(); // } }//eoc }//eons