private static void PrintColorized(string Prefix, Color PrefixColor, bool exit, IEnumerable <object> msg) { Console.OutputEncoding = System.Text.Encoding.UTF8; var color = PrefixColor; var m = msg.Aggregate(string.Empty, (current, x) => current + " " + x); Console.WriteFormatted(Prefix, color); color = Color.White; foreach (var x in Regex.Split(m, @"\%(.*?)\%")) { if (!x.StartsWith("#") || !Hex.IsHex(x.TrimStart('#')) || x.Length != 7) { Console.WriteFormatted(x, color); continue; } color = Color.FromArgb(int.Parse(x.Replace("#", "").ToUpper().Trim(), NumberStyles.HexNumber)); } Console.WriteLine(); if (exit) { Environment.Exit(1); } }
public static (string password, byte[] salt) generate_hash(string password, int rounds = 20) { var pwBytes = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password); var saltBytes = generate_salt(); var pwHashBytes = scr.Generate(pwBytes, saltBytes, 262144 / 4, rounds, 1, 512); return(Convert.ToBase64String(pwHashBytes), saltBytes); }
public static bool validate_password(string password, string hash, byte[] salt, int rounds = 20) { var pwBytes = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password); var pwHashBytes = scr.Generate(pwBytes, salt, 262144 / 4, rounds, 1, 512); var hashBytes = Convert.FromBase64String(hash); return(pwHashBytes.SequenceEqual(hashBytes)); }