- All Superinterfaces:
Cloneable,Serializable
- All Known Implementing Classes:
HashImpl
@ClassVersion(sourceVersion="$Id: Hash.java 1052 2023-03-06 06:30:36Z tquadrat $")
@API(status=STABLE,
since="0.1.1")
public sealed interface Hash
extends Cloneable, Serializable
permits HashImpl
The definition for a wrapper around hash values of any kind. These hashes are often used as checksums to validate the integrity of files or messages.
- Author:
- Thomas Thrien (thomas.thrien@tquadrat.org)
- Version:
- $Id: Hash.java 1052 2023-03-06 06:30:36Z tquadrat $
- Since:
- 0.1.1
- UML Diagram
-
UML Diagram for "org.tquadrat.foundation.util.Hash"
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]bytes()Returns the hash as an array of bytes.clone()Creates and returns a copy of this object.static Hashcreate(byte[] data, MessageDigest algorithm) Creates the hash for the given byte array, using the given algorithm.static HashCreates the hash for the given byte array, using the given algorithm.static Hashcreate(File data, MessageDigest algorithm) Creates the hash for the given file, using the given algorithm.static HashCreates the hash for the given file, using the given algorithm.static Hashcreate(CharSequence data, Charset encoding, MessageDigest algorithm) Creates the hash for the given String, using the given algorithm.static Hashcreate(CharSequence data, Charset encoding, Checksum algorithm) Creates the hash for the given String, using the given algorithm.static Hashcreate(CharSequence data, MessageDigest algorithm) Creates the hash for the given String, using the given algorithm.static Hashcreate(CharSequence data, Checksum algorithm) Creates the hash for the given String, using the given algorithm.static Hashcreate(Path data, MessageDigest algorithm) Creates the hash for the given file, using the given algorithm.static HashCreates the hash for the given file, using the given algorithm.static Hashfrom(byte[] hashValue) Creates an instance ofHashfrom the given byte array.static Hashfrom(CharSequence hashValue) Creates an instance ofHashfrom the given String.default BigIntegernumber()Returns this hash as a number.default booleanvalidate(byte[] hashValue) Validates whether the given hash value matches with this hash instance.default booleanvalidate(long hashValue) Validates whether the given hash value matches with this hash instance.default booleanvalidate(CharSequence hashValue) Validates whether the given hash value matches with this hash instance.
-
Method Details
-
bytes
byte[] bytes()Returns the hash as an array of bytes.- Returns:
- The hash value.
-
clone
Creates and returns a copy of this object.- Returns:
- The copy of this instance.
-
create
Creates the hash for the given byte array, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given String, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given String, using the given algorithm.- Parameters:
data- The input data.encoding- The encoding for the String.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given file, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash. - Throws:
IOException- Problems to process the file.
-
create
Creates the hash for the given file, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash. - Throws:
IOException- Problems to process the file.
-
create
Creates the hash for the given byte array, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given String, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given String, using the given algorithm.- Parameters:
data- The input data.encoding- The encoding for the String.algorithm- The algorithm- Returns:
- A new instance of
Hash.
-
create
Creates the hash for the given file, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash. - Throws:
IOException- Problems to process the file.
-
create
Creates the hash for the given file, using the given algorithm.- Parameters:
data- The input data.algorithm- The algorithm- Returns:
- A new instance of
Hash. - Throws:
IOException- Problems to process the file.
-
from
Creates an instance ofHashfrom the given byte array.- Parameters:
hashValue- The hash value.- Returns:
- A new instance of
Hash.
-
from
Creates an instance ofHashfrom the given String.- Parameters:
hashValue- The hash value.- Returns:
- A new instance of
Hash.
-
number
Returns this hash as a number.- Returns:
- The number.
-
validate
Validates whether the given hash value matches with this hash instance.- Parameters:
hashValue- The hash value to test.- Returns:
trueif the hash value matches with this hash instance,falseotherwise.
-
validate
Validates whether the given hash value matches with this hash instance.- Parameters:
hashValue- The hash value to test.- Returns:
trueif the hash value matches with this hash instance,falseotherwise.
-
validate
Validates whether the given hash value matches with this hash instance.- Parameters:
hashValue- The hash value to test.- Returns:
trueif the hash value matches with this hash instance,falseotherwise.
-
