/// <summary> /// Hashes the given phrase. /// </summary> /// <param name="phrase">Phrase to hash.</param> /// <returns>Hash of <paramref name="phrase" /> as a string.</returns> /// <exception cref="T:System.ArgumentNullException"><paramref name="phrase" /> is null.</exception> public string Hash(ClearPhrase phrase) { if (phrase == null) { throw new ArgumentNullException(nameof(phrase)); } byte[] bytes = phrase.ToBytes(); var hash = _hashAlgorithm.Hash(bytes); return(_encoder.Encode(hash)); }
/// <summary> /// Verify that the hash of <paramref name="phrase" /> is equal to <paramref name="expectedHash" />. /// </summary> /// <param name="phrase">Clear text phrase.</param> /// <param name="expectedHash">Hashed phrase.</param> /// <returns>True if phrase and hashed phrase are equal; otherwise returns false.</returns> /// <exception cref="T:System.ArgumentNullException"><paramref name="phrase" /> is null.</exception> /// <exception cref="T:System.ArgumentNullException"><paramref name="expectedHash" /> is null.</exception> public bool Verify(ClearPhrase phrase, string expectedHash) { if (phrase == null) { throw new ArgumentNullException(nameof(phrase)); } if (expectedHash == null) { throw new ArgumentNullException(nameof(expectedHash)); } var hash = Hash(phrase); return(expectedHash .FormatChecksum(_encodingType) .Equals(hash, StringComparison.Ordinal)); }