public class DigestUtils
extends java.lang.Object
MessageDigest tasks.
This class is immutable and thread-safe.| Modifier and Type | Field and Description |
|---|---|
private static int |
STREAM_BUFFER_LENGTH |
| Constructor and Description |
|---|
DigestUtils() |
| Modifier and Type | Method and Description |
|---|---|
private static byte[] |
digest(java.security.MessageDigest digest,
java.io.InputStream data)
Read through an InputStream and returns the digest for the data
|
static java.security.MessageDigest |
getDigest(java.lang.String algorithm)
Returns a
MessageDigest for the given algorithm. |
static java.security.MessageDigest |
getMd2Digest()
Returns an MD2 MessageDigest.
|
static java.security.MessageDigest |
getMd5Digest()
Returns an MD5 MessageDigest.
|
static java.security.MessageDigest |
getSha1Digest()
Returns an SHA-1 digest.
|
static java.security.MessageDigest |
getSha256Digest()
Returns an SHA-256 digest.
|
static java.security.MessageDigest |
getSha384Digest()
Returns an SHA-384 digest.
|
static java.security.MessageDigest |
getSha512Digest()
Returns an SHA-512 digest.
|
static java.security.MessageDigest |
getShaDigest()
Deprecated.
Use
getSha1Digest() |
static byte[] |
md2(byte[] data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md2(java.io.InputStream data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md2(java.lang.String data)
Calculates the MD2 digest and returns the value as a 16 element
byte[]. |
static java.lang.String |
md2Hex(byte[] data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static java.lang.String |
md2Hex(java.io.InputStream data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static java.lang.String |
md2Hex(java.lang.String data)
Calculates the MD2 digest and returns the value as a 32 character hex string.
|
static byte[] |
md5(byte[] data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md5(java.io.InputStream data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static byte[] |
md5(java.lang.String data)
Calculates the MD5 digest and returns the value as a 16 element
byte[]. |
static java.lang.String |
md5Hex(byte[] data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static java.lang.String |
md5Hex(java.io.InputStream data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static java.lang.String |
md5Hex(java.lang.String data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static byte[] |
sha(byte[] data)
Deprecated.
Use
sha1(byte[]) |
static byte[] |
sha(java.io.InputStream data)
Deprecated.
|
static byte[] |
sha(java.lang.String data)
Deprecated.
Use
sha1(String) |
static byte[] |
sha1(byte[] data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static byte[] |
sha1(java.io.InputStream data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static byte[] |
sha1(java.lang.String data)
Calculates the SHA-1 digest and returns the value as a
byte[]. |
static java.lang.String |
sha1Hex(byte[] data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static java.lang.String |
sha1Hex(java.io.InputStream data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static java.lang.String |
sha1Hex(java.lang.String data)
Calculates the SHA-1 digest and returns the value as a hex string.
|
static byte[] |
sha256(byte[] data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static byte[] |
sha256(java.io.InputStream data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static byte[] |
sha256(java.lang.String data)
Calculates the SHA-256 digest and returns the value as a
byte[]. |
static java.lang.String |
sha256Hex(byte[] data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static java.lang.String |
sha256Hex(java.io.InputStream data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static java.lang.String |
sha256Hex(java.lang.String data)
Calculates the SHA-256 digest and returns the value as a hex string.
|
static byte[] |
sha384(byte[] data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static byte[] |
sha384(java.io.InputStream data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static byte[] |
sha384(java.lang.String data)
Calculates the SHA-384 digest and returns the value as a
byte[]. |
static java.lang.String |
sha384Hex(byte[] data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static java.lang.String |
sha384Hex(java.io.InputStream data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static java.lang.String |
sha384Hex(java.lang.String data)
Calculates the SHA-384 digest and returns the value as a hex string.
|
static byte[] |
sha512(byte[] data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static byte[] |
sha512(java.io.InputStream data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static byte[] |
sha512(java.lang.String data)
Calculates the SHA-512 digest and returns the value as a
byte[]. |
static java.lang.String |
sha512Hex(byte[] data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
static java.lang.String |
sha512Hex(java.io.InputStream data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
static java.lang.String |
sha512Hex(java.lang.String data)
Calculates the SHA-512 digest and returns the value as a hex string.
|
static java.lang.String |
shaHex(byte[] data)
Deprecated.
Use
sha1Hex(byte[]) |
static java.lang.String |
shaHex(java.io.InputStream data)
Deprecated.
|
static java.lang.String |
shaHex(java.lang.String data)
Deprecated.
Use
sha1Hex(String) |
static java.security.MessageDigest |
updateDigest(java.security.MessageDigest messageDigest,
byte[] valueToDigest)
Updates the given
MessageDigest. |
static java.security.MessageDigest |
updateDigest(java.security.MessageDigest digest,
java.io.InputStream data)
Reads through an InputStream and updates the digest for the data
|
static java.security.MessageDigest |
updateDigest(java.security.MessageDigest messageDigest,
java.lang.String valueToDigest)
Updates the given
MessageDigest. |
private static final int STREAM_BUFFER_LENGTH
private static byte[] digest(java.security.MessageDigest digest,
java.io.InputStream data)
throws java.io.IOException
digest - The MessageDigest to use (e.g. MD5)data - Data to digestjava.io.IOException - On error reading from the streampublic static java.security.MessageDigest getDigest(java.lang.String algorithm)
MessageDigest for the given algorithm.algorithm - the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture Reference Guide for information about standard
algorithm names.java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught.MessageDigest.getInstance(String)public static java.security.MessageDigest getMd2Digest()
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD2 is a
built-in algorithmMessageDigestAlgorithms.MD2public static java.security.MessageDigest getMd5Digest()
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because MD5 is a
built-in algorithmMessageDigestAlgorithms.MD5public static java.security.MessageDigest getSha1Digest()
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-1 is a
built-in algorithmMessageDigestAlgorithms.SHA_1public static java.security.MessageDigest getSha256Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-256 is a
built-in algorithmMessageDigestAlgorithms.SHA_256public static java.security.MessageDigest getSha384Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-384 is a
built-in algorithmMessageDigestAlgorithms.SHA_384public static java.security.MessageDigest getSha512Digest()
Throws a RuntimeException on JRE versions prior to 1.4.0.
java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caught, which should never happen because SHA-512 is a
built-in algorithmMessageDigestAlgorithms.SHA_512@Deprecated public static java.security.MessageDigest getShaDigest()
getSha1Digest()java.lang.IllegalArgumentException - when a NoSuchAlgorithmException is caughtpublic static byte[] md2(byte[] data)
byte[].data - Data to digestpublic static byte[] md2(java.io.InputStream data)
throws java.io.IOException
byte[].data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] md2(java.lang.String data)
byte[].data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String md2Hex(byte[] data)
data - Data to digestpublic static java.lang.String md2Hex(java.io.InputStream data)
throws java.io.IOException
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String md2Hex(java.lang.String data)
data - Data to digestpublic static byte[] md5(byte[] data)
byte[].data - Data to digestpublic static byte[] md5(java.io.InputStream data)
throws java.io.IOException
byte[].data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] md5(java.lang.String data)
byte[].data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String md5Hex(byte[] data)
data - Data to digestpublic static java.lang.String md5Hex(java.io.InputStream data)
throws java.io.IOException
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String md5Hex(java.lang.String data)
data - Data to digest@Deprecated public static byte[] sha(byte[] data)
sha1(byte[])byte[].data - Data to digest@Deprecated
public static byte[] sha(java.io.InputStream data)
throws java.io.IOException
sha1(InputStream)byte[].data - Data to digestjava.io.IOException - On error reading from the stream@Deprecated public static byte[] sha(java.lang.String data)
sha1(String)byte[].data - Data to digestpublic static byte[] sha1(byte[] data)
byte[].data - Data to digestpublic static byte[] sha1(java.io.InputStream data)
throws java.io.IOException
byte[].data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] sha1(java.lang.String data)
byte[].data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String sha1Hex(byte[] data)
data - Data to digestpublic static java.lang.String sha1Hex(java.io.InputStream data)
throws java.io.IOException
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String sha1Hex(java.lang.String data)
data - Data to digestpublic static byte[] sha256(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha256(java.io.InputStream data)
throws java.io.IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] sha256(java.lang.String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String sha256Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static java.lang.String sha256Hex(java.io.InputStream data)
throws java.io.IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String sha256Hex(java.lang.String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha384(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha384(java.io.InputStream data)
throws java.io.IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] sha384(java.lang.String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String sha384Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static java.lang.String sha384Hex(java.io.InputStream data)
throws java.io.IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String sha384Hex(java.lang.String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha512(byte[] data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static byte[] sha512(java.io.InputStream data)
throws java.io.IOException
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static byte[] sha512(java.lang.String data)
byte[].
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest; converted to bytes using StringUtils.getBytesUtf8(String)public static java.lang.String sha512Hex(byte[] data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestpublic static java.lang.String sha512Hex(java.io.InputStream data)
throws java.io.IOException
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digestjava.io.IOException - On error reading from the streampublic static java.lang.String sha512Hex(java.lang.String data)
Throws a RuntimeException on JRE versions prior to 1.4.0.
data - Data to digest@Deprecated public static java.lang.String shaHex(byte[] data)
sha1Hex(byte[])data - Data to digest@Deprecated
public static java.lang.String shaHex(java.io.InputStream data)
throws java.io.IOException
sha1Hex(InputStream)data - Data to digestjava.io.IOException - On error reading from the stream@Deprecated public static java.lang.String shaHex(java.lang.String data)
sha1Hex(String)data - Data to digestpublic static java.security.MessageDigest updateDigest(java.security.MessageDigest messageDigest,
byte[] valueToDigest)
MessageDigest.messageDigest - the MessageDigest to updatevalueToDigest - the value to update the MessageDigest withMessageDigestpublic static java.security.MessageDigest updateDigest(java.security.MessageDigest digest,
java.io.InputStream data)
throws java.io.IOException
digest - The MessageDigest to use (e.g. MD5)data - Data to digestjava.io.IOException - On error reading from the streampublic static java.security.MessageDigest updateDigest(java.security.MessageDigest messageDigest,
java.lang.String valueToDigest)
MessageDigest.messageDigest - the MessageDigest to updatevalueToDigest - the value to update the MessageDigest with;
converted to bytes using StringUtils.getBytesUtf8(String)MessageDigestcommons-codec version 1.10-SNAPSHOT - Copyright © 2002-2015 - Apache Software Foundation