@Immutable public class SecureHash extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SecureHash.Algorithm
Commonly-used hashing algorithms.
|
static class |
SecureHash.HashingInputStream |
static class |
SecureHash.HashingReader |
Modifier and Type | Method and Description |
---|---|
static String |
asHexString(byte[] hash)
Get the string representation of the supplied binary hash.
|
static SecureHash.HashingReader |
createHashingReader(SecureHash.Algorithm algorithm,
Reader reader,
Charset charset)
Create an Reader instance that wraps another reader and that computes the secure hash (using the algorithm with the
supplied name) as the returned Reader is used.
|
static SecureHash.HashingReader |
createHashingReader(String digestName,
Reader reader,
Charset charset)
Create an Reader instance that wraps another reader and that computes the secure hash (using the algorithm with the
supplied name) as the returned Reader is used.
|
static SecureHash.HashingInputStream |
createHashingStream(SecureHash.Algorithm algorithm,
InputStream inputStream)
Create an InputStream instance that wraps another stream and that computes the secure hash (using the algorithm with the
supplied name) as the returned stream is used.
|
static SecureHash.HashingInputStream |
createHashingStream(String digestName,
InputStream inputStream)
Create an InputStream instance that wraps another stream and that computes the secure hash (using the algorithm with the
supplied name) as the returned stream is used.
|
static byte[] |
getHash(SecureHash.Algorithm algorithm,
byte[] content)
Get the hash of the supplied content, using the supplied digest algorithm.
|
static byte[] |
getHash(SecureHash.Algorithm algorithm,
File file)
Get the hash of the supplied content, using the supplied digest algorithm.
|
static byte[] |
getHash(SecureHash.Algorithm algorithm,
InputStream stream)
Get the hash of the supplied content, using the supplied digest algorithm.
|
static byte[] |
getHash(String digestName,
byte[] content)
Get the hash of the supplied content, using the digest identified by the supplied name.
|
static byte[] |
getHash(String digestName,
File file)
Get the hash of the supplied content, using the digest identified by the supplied name.
|
static byte[] |
getHash(String digestName,
InputStream stream)
Get the hash of the supplied content, using the digest identified by the supplied name.
|
static String |
sha1(String string)
Computes the sha1 value for the given string.
|
public static byte[] getHash(SecureHash.Algorithm algorithm, byte[] content) throws NoSuchAlgorithmException
algorithm
- the hashing function algorithm that should be usedcontent
- the content to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundIllegalArgumentException
- if the algorithm is nullpublic static byte[] getHash(SecureHash.Algorithm algorithm, File file) throws NoSuchAlgorithmException, IOException
algorithm
- the hashing function algorithm that should be usedfile
- the file containing the content to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundIllegalArgumentException
- if the algorithm is nullIOException
- if there is an error reading the filepublic static byte[] getHash(SecureHash.Algorithm algorithm, InputStream stream) throws NoSuchAlgorithmException, IOException
algorithm
- the hashing function algorithm that should be usedstream
- the stream containing the content to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundIllegalArgumentException
- if the algorithm is nullIOException
- if there is an error reading the streampublic static byte[] getHash(String digestName, byte[] content) throws NoSuchAlgorithmException
digestName
- the name of the hashing function (or message digest
) that should be usedcontent
- the content to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundpublic static byte[] getHash(String digestName, File file) throws NoSuchAlgorithmException, IOException
digestName
- the name of the hashing function (or message digest
) that should be usedfile
- the file whose content is to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundIOException
- if there is an error reading the filepublic static byte[] getHash(String digestName, InputStream stream) throws NoSuchAlgorithmException, IOException
digestName
- the name of the hashing function (or message digest
) that should be usedstream
- the stream containing the content to be hashed; may not be nullNoSuchAlgorithmException
- if the supplied algorithm could not be foundIOException
- if there is an error reading the streampublic static SecureHash.HashingInputStream createHashingStream(SecureHash.Algorithm algorithm, InputStream inputStream) throws NoSuchAlgorithmException
algorithm
- the hashing function algorithm that should be usedinputStream
- the stream containing the content that is to be hashedNoSuchAlgorithmException
public static SecureHash.HashingInputStream createHashingStream(String digestName, InputStream inputStream) throws NoSuchAlgorithmException
digestName
- the name of the hashing function (or message digest
) that should be usedinputStream
- the stream containing the content that is to be hashedNoSuchAlgorithmException
public static SecureHash.HashingReader createHashingReader(SecureHash.Algorithm algorithm, Reader reader, Charset charset) throws NoSuchAlgorithmException
algorithm
- the hashing function algorithm that should be usedreader
- the reader containing the content that is to be hashedcharset
- the character set used within the supplied reader; may not be nullNoSuchAlgorithmException
public static SecureHash.HashingReader createHashingReader(String digestName, Reader reader, Charset charset) throws NoSuchAlgorithmException
digestName
- the name of the hashing function (or message digest
) that should be usedreader
- the reader containing the content that is to be hashedcharset
- the character set used within the supplied reader; may not be nullNoSuchAlgorithmException
public static String asHexString(byte[] hash)
hash
- the binary hashCopyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.