Top Description Fields Constructors Methods
org.springframework.util

public abstract Class DigestUtils

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, java.security.MessageDigest, .NoSuchAlgorithmException

Miscellaneous methods for calculating digests.

Mainly for internal use within the framework; consider Apache Commons Codec for a more comprehensive suite of digest utilities.

Authors
Arjen Poutsma, Juergen Hoeller, Craig Andrews
Since
3.0

Field Summary

Modifier and TypeField and Description
private static final char[]
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static StringBuilder
appendDigestAsHex(String algorithm, byte[] bytes, StringBuilder builder)

private static StringBuilder
appendDigestAsHex(String algorithm, InputStream inputStream, StringBuilder builder)

public static StringBuilder

Returns:

the given string builder
appendMd5DigestAsHex
(byte[]
the bytes to calculate the digest over
bytes
,
StringBuilder
the string builder to append the digest to
builder
)

Append a hexadecimal string representation of the MD5 digest of the given bytes to the given StringBuilder.

public static StringBuilder

Returns:

the given string builder
appendMd5DigestAsHex
(InputStream
the inputStream to calculate the digest over
inputStream
,
StringBuilder
the string builder to append the digest to
builder
)

Append a hexadecimal string representation of the MD5 digest of the given inputStream to the given StringBuilder.

private static byte[]
digest(String algorithm, byte[] bytes)

private static byte[]
digest(String algorithm, InputStream inputStream)

private static char[]
digestAsHexChars(String algorithm, byte[] bytes)

private static char[]
digestAsHexChars(String algorithm, InputStream inputStream)

private static String
digestAsHexString(String algorithm, byte[] bytes)

private static String
digestAsHexString(String algorithm, InputStream inputStream)

private static char[]
encodeHex(byte[] bytes)

private static MessageDigest
getDigest(String algorithm)

Create a new MessageDigest with the given algorithm.

public static byte[]

Returns:

the digest
md5Digest
(byte[]
the bytes to calculate the digest over
bytes
)

Calculate the MD5 digest of the given bytes.

public static byte[]

Returns:

the digest
md5Digest
(InputStream
the InputStream to calculate the digest over
inputStream
)

Calculate the MD5 digest of the given stream.

public static String

Returns:

a hexadecimal digest string
md5DigestAsHex
(byte[]
the bytes to calculate the digest over
bytes
)

Return a hexadecimal string representation of the MD5 digest of the given bytes.

public static String

Returns:

a hexadecimal digest string
md5DigestAsHex
(InputStream
the InputStream to calculate the digest over
inputStream
)

Return a hexadecimal string representation of the MD5 digest of the given stream.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEX_CHARSback to summary
private static final char[] HEX_CHARS
MD5_ALGORITHM_NAMEback to summary
private static final String MD5_ALGORITHM_NAME

Constructor Detail

DigestUtilsback to summary
public DigestUtils()

Method Detail

appendDigestAsHexback to summary
private static StringBuilder appendDigestAsHex(String algorithm, byte[] bytes, StringBuilder builder)
appendDigestAsHexback to summary
private static StringBuilder appendDigestAsHex(String algorithm, InputStream inputStream, StringBuilder builder) throws IOException
appendMd5DigestAsHexback to summary
public static StringBuilder appendMd5DigestAsHex(byte[] bytes, StringBuilder builder)

Append a hexadecimal string representation of the MD5 digest of the given bytes to the given StringBuilder.

Parameters
bytes:byte[]

the bytes to calculate the digest over

builder:StringBuilder

the string builder to append the digest to

Returns:StringBuilder

the given string builder

appendMd5DigestAsHexback to summary
public static StringBuilder appendMd5DigestAsHex(InputStream inputStream, StringBuilder builder) throws IOException

Append a hexadecimal string representation of the MD5 digest of the given inputStream to the given StringBuilder.

This method does not close the input stream.

Parameters
inputStream:InputStream

the inputStream to calculate the digest over

builder:StringBuilder

the string builder to append the digest to

Returns:StringBuilder

the given string builder

Since
4.2
digestback to summary
private static byte[] digest(String algorithm, byte[] bytes)
digestback to summary
private static byte[] digest(String algorithm, InputStream inputStream) throws IOException
digestAsHexCharsback to summary
private static char[] digestAsHexChars(String algorithm, byte[] bytes)
digestAsHexCharsback to summary
private static char[] digestAsHexChars(String algorithm, InputStream inputStream) throws IOException
digestAsHexStringback to summary
private static String digestAsHexString(String algorithm, byte[] bytes)
digestAsHexStringback to summary
private static String digestAsHexString(String algorithm, InputStream inputStream) throws IOException
encodeHexback to summary
private static char[] encodeHex(byte[] bytes)
getDigestback to summary
private static MessageDigest getDigest(String algorithm)

Create a new MessageDigest with the given algorithm.

Necessary because MessageDigest is not thread-safe.

md5Digestback to summary
public static byte[] md5Digest(byte[] bytes)

Calculate the MD5 digest of the given bytes.

Parameters
bytes:byte[]

the bytes to calculate the digest over

Returns:byte[]

the digest

md5Digestback to summary
public static byte[] md5Digest(InputStream inputStream) throws IOException

Calculate the MD5 digest of the given stream.

This method does not close the input stream.

Parameters
inputStream:InputStream

the InputStream to calculate the digest over

Returns:byte[]

the digest

Since
4.2
md5DigestAsHexback to summary
public static String md5DigestAsHex(byte[] bytes)

Return a hexadecimal string representation of the MD5 digest of the given bytes.

Parameters
bytes:byte[]

the bytes to calculate the digest over

Returns:String

a hexadecimal digest string

md5DigestAsHexback to summary
public static String md5DigestAsHex(InputStream inputStream) throws IOException

Return a hexadecimal string representation of the MD5 digest of the given stream.

This method does not close the input stream.

Parameters
inputStream:InputStream

the InputStream to calculate the digest over

Returns:String

a hexadecimal digest string

Since
4.2