Table of Contents

Class HashExtensions

Namespace
Tharga.Toolkit
Assembly
Tharga.Toolkit.dll

Extension methods for computing hash values from bytes, strings, URIs, and streams.

public static class HashExtensions
Inheritance
HashExtensions
Inherited Members

Methods

ChangeFormat(HashString, HashFormat)

Converts a HashString to a different output format.

public static HashString ChangeFormat(this HashString hash, HashFormat format)

Parameters

hash HashString
format HashFormat

Returns

HashString

FormatHash(Hash, HashFormat)

Formats a raw Hash into a HashString using the specified format.

public static HashString FormatHash(this Hash hash, HashFormat format)

Parameters

hash Hash
format HashFormat

Returns

HashString

ToHash(byte[], HashFormat, HashType)

Computes a hash of the byte array and returns a formatted string representation.

public static HashString ToHash(this byte[] item, HashFormat format, HashType type = HashType.MD5)

Parameters

item byte[]
format HashFormat
type HashType

Returns

HashString

ToHash(byte[], HashType)

Computes a hash of the specified byte array.

public static Hash ToHash(this byte[] item, HashType type = HashType.MD5)

Parameters

item byte[]

The data to hash.

type HashType

The hash algorithm to use. Defaults to MD5.

Returns

Hash

A Hash containing the computed hash, or null if the input is null or empty.

ToHash(string, HashFormat, HashType, Encoding)

Computes a hash of the string and returns a formatted string representation.

public static HashString ToHash(this string item, HashFormat format, HashType type = HashType.MD5, Encoding encoding = null)

Parameters

item string
format HashFormat
type HashType
encoding Encoding

Returns

HashString

ToHash(string, HashType, Encoding)

Computes a hash of the specified string.

public static Hash ToHash(this string item, HashType type = HashType.MD5, Encoding encoding = null)

Parameters

item string

The string to hash.

type HashType

The hash algorithm to use. Defaults to MD5.

encoding Encoding

The encoding to use. Defaults to UTF-8.

Returns

Hash

A Hash containing the computed hash, or null if the input is null or empty.

ToHash(Uri, HashFormat, HashType, Encoding)

Computes a hash of the URI and returns a formatted string representation.

public static HashString ToHash(this Uri item, HashFormat format, HashType type = HashType.MD5, Encoding encoding = null)

Parameters

item Uri
format HashFormat
type HashType
encoding Encoding

Returns

HashString

ToHash(Uri, HashType, Encoding)

Computes a hash of the URI's absolute string representation.

public static Hash ToHash(this Uri item, HashType type = HashType.MD5, Encoding encoding = null)

Parameters

item Uri
type HashType
encoding Encoding

Returns

Hash

ToHashAndOutputAsync(Stream, Stream, HashFormat, HashType)

Asynchronously computes a hash while copying the stream, returning a formatted string.

public static Task<HashString> ToHashAndOutputAsync(this Stream input, Stream output, HashFormat format, HashType type = HashType.MD5)

Parameters

input Stream
output Stream
format HashFormat
type HashType

Returns

Task<HashString>

ToHashAndOutputAsync(Stream, Stream, HashType)

Asynchronously computes a hash while copying the stream content to an output stream.

public static Task<Hash> ToHashAndOutputAsync(this Stream input, Stream output, HashType type = HashType.MD5)

Parameters

input Stream
output Stream
type HashType

Returns

Task<Hash>

ToHashAsync(Stream, HashFormat, HashType)

Asynchronously computes a hash from a stream and returns a formatted string representation.

public static Task<HashString> ToHashAsync(this Stream stream, HashFormat format, HashType type = HashType.MD5)

Parameters

stream Stream
format HashFormat
type HashType

Returns

Task<HashString>

ToHashAsync(Stream, HashType)

Asynchronously computes a hash from a stream.

public static Task<Hash> ToHashAsync(this Stream stream, HashType type = HashType.MD5)

Parameters

stream Stream
type HashType

Returns

Task<Hash>

UnformatHash(HashString)

Converts a formatted HashString back to a raw Hash.

public static Hash UnformatHash(this HashString hash)

Parameters

hash HashString

Returns

Hash