public static string GetHash(string password, string salt) { var passwordWithSalt = password + salt; var sha256CryptoServiceProvider = new SHA256CryptoServiceProvider(); sha256CryptoServiceProvider.Initialize(); var bytes = Encoding.UTF8.GetBytes(passwordWithSalt.ToCharArray()); var sha256 = sha256CryptoServiceProvider.ComputeHash(bytes); var sha256String = Encoding.UTF8.GetString(sha256); return(sha256String); }
private byte[] GetTokenKey(IConfigurationRoot config) { var secret = config.GetSection("TokenSecret")?.GetValue("SecretKey", ""); if (string.IsNullOrWhiteSpace(secret)) { throw new InvalidOperationException( "Could not find a token secret named 'SecretKey'."); } using (HashAlgorithm hash = new SHA256CryptoServiceProvider()) { hash.Initialize(); return(hash.ComputeHash(Encoding.UTF8.GetBytes(secret))); } }
private byte[] ValidatePassword(byte[] paddedPassword) { sha256.Initialize(); return(sha256.ComputeHash(paddedPassword)); }
/// <summary> /// Generate a SHA-256 hash from the given bytes. /// </summary> /// <param name="input">Bytes to generate a hash from.</param> /// <returns>A SHA-256 hash.</returns> public static byte[] Generate(byte[] input) { sha256csp.Initialize(); return(sha256csp.ComputeHash(input)); }