org.apache.commons.codec.digest

Class DigestUtils

public class DigestUtils extends Object

Operations to simplifiy common {@link java.security.MessageDigest} tasks. This class is thread safe.

Author: Apache Software Foundation

Method Summary
static MessageDigestgetDigest(String algorithm)
Returns a MessageDigest for the given algorithm.
static MessageDigestgetMd5Digest()
Returns an MD5 MessageDigest.
static MessageDigestgetShaDigest()
Returns an SHA digest.
static byte[]md5(byte[] data)
Calculates the MD5 digest and returns the value as a 16 element byte[].
static byte[]md5(String data)
Calculates the MD5 digest and returns the value as a 16 element byte[].
static Stringmd5Hex(byte[] data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
static Stringmd5Hex(String data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
static byte[]sha(byte[] data)
Calculates the SHA digest and returns the value as a byte[].
static byte[]sha(String data)
Calculates the SHA digest and returns the value as a byte[].
static StringshaHex(byte[] data)
Calculates the SHA digest and returns the value as a hex string.
static StringshaHex(String data)
Calculates the SHA digest and returns the value as a hex string.

Method Detail

getDigest

static MessageDigest getDigest(String algorithm)
Returns a MessageDigest for the given algorithm.

Parameters: algorithm The MessageDigest algorithm name.

Returns: An MD5 digest instance.

Throws: RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,

getMd5Digest

private static MessageDigest getMd5Digest()
Returns an MD5 MessageDigest.

Returns: An MD5 digest instance.

Throws: RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,

getShaDigest

private static MessageDigest getShaDigest()
Returns an SHA digest.

Returns: An SHA digest instance.

Throws: RuntimeException when a {@link java.security.NoSuchAlgorithmException} is caught,

md5

public static byte[] md5(byte[] data)
Calculates the MD5 digest and returns the value as a 16 element byte[].

Parameters: data Data to digest

Returns: MD5 digest

md5

public static byte[] md5(String data)
Calculates the MD5 digest and returns the value as a 16 element byte[].

Parameters: data Data to digest

Returns: MD5 digest

md5Hex

public static String md5Hex(byte[] data)
Calculates the MD5 digest and returns the value as a 32 character hex string.

Parameters: data Data to digest

Returns: MD5 digest as a hex string

md5Hex

public static String md5Hex(String data)
Calculates the MD5 digest and returns the value as a 32 character hex string.

Parameters: data Data to digest

Returns: MD5 digest as a hex string

sha

public static byte[] sha(byte[] data)
Calculates the SHA digest and returns the value as a byte[].

Parameters: data Data to digest

Returns: SHA digest

sha

public static byte[] sha(String data)
Calculates the SHA digest and returns the value as a byte[].

Parameters: data Data to digest

Returns: SHA digest

shaHex

public static String shaHex(byte[] data)
Calculates the SHA digest and returns the value as a hex string.

Parameters: data Data to digest

Returns: SHA digest as a hex string

shaHex

public static String shaHex(String data)
Calculates the SHA digest and returns the value as a hex string.

Parameters: data Data to digest

Returns: SHA digest as a hex string

commons-codec version 1.3 - Copyright © 2002-2004 - Apache Software Foundation