Package org.elasticsearch.common.hash
Class MessageDigests
java.lang.Object
org.elasticsearch.common.hash.MessageDigests
This MessageDigests class provides convenience methods for obtaining
thread local
MessageDigest
instances for MD5, SHA-1, SHA-256 and
SHA-512 message digests.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
digest(BytesReference bytesReference, MessageDigest digest)
Updates the given digest with the given bytes reference and the returns the result of the digest.static MessageDigest
md5()
Returns aMessageDigest
instance for MD5 digests; note that the instance returned is thread local and must not be shared amongst threads.static MessageDigest
sha1()
Returns aMessageDigest
instance for SHA-1 digests; note that the instance returned is thread local and must not be shared amongst threads.static MessageDigest
sha256()
Returns aMessageDigest
instance for SHA-256 digests; note that the instance returned is thread local and must not be shared amongst threads.static MessageDigest
sha512()
Returns aMessageDigest
instance for SHA-512 digests; note that the instance returned is thread local and must not be shared amongst threads.static char[]
toHexCharArray(byte[] bytes)
Encodes the byte array into a newly created hex char array, without allocating any other temporary variables.static String
toHexString(byte[] bytes)
Format a byte array as a hex string.
-
Constructor Details
-
MessageDigests
public MessageDigests()
-
-
Method Details
-
md5
Returns aMessageDigest
instance for MD5 digests; note that the instance returned is thread local and must not be shared amongst threads.- Returns:
- a thread local
MessageDigest
instance that provides MD5 message digest functionality.
-
sha1
Returns aMessageDigest
instance for SHA-1 digests; note that the instance returned is thread local and must not be shared amongst threads.- Returns:
- a thread local
MessageDigest
instance that provides SHA-1 message digest functionality.
-
sha256
Returns aMessageDigest
instance for SHA-256 digests; note that the instance returned is thread local and must not be shared amongst threads.- Returns:
- a thread local
MessageDigest
instance that provides SHA-256 message digest functionality.
-
sha512
Returns aMessageDigest
instance for SHA-512 digests; note that the instance returned is thread local and must not be shared amongst threads.- Returns:
- a thread local
MessageDigest
instance that provides SHA-512 message digest functionality.
-
toHexString
Format a byte array as a hex string.- Parameters:
bytes
- the input to be represented as hex.- Returns:
- a hex representation of the input as a String.
-
toHexCharArray
public static char[] toHexCharArray(byte[] bytes)Encodes the byte array into a newly created hex char array, without allocating any other temporary variables.- Parameters:
bytes
- the input to be encoded as hex.- Returns:
- the hex encoding of the input as a char array.
-
digest
Updates the given digest with the given bytes reference and the returns the result of the digest.- Parameters:
bytesReference
- bytes to add to digestdigest
- digest to update and return the result for- Returns:
- digest result
-