Java Utililty Methods Digest

List of utility methods to do Digest

Description

The list of methods to do Digest are organized into topic(s).

Method

byte[]digest(byte[] buffer)
calculate fingerprint of a given byte[] using SHA-1 agorithm
return digest(SHA_1, buffer);
Stringdigest(byte[] bytes)
digest
MessageDigest sha = MessageDigest.getInstance("SHA");
byte[] digest = sha.digest(bytes);
BASE64Encoder base64Encoder = new BASE64Encoder();
return base64Encoder.encode(digest);
Stringdigest(byte[] bytes, String algorithm)
digest
try {
    MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
    byte[] digest = messageDigest.digest(bytes);
    return Base64.getEncoder().encodeToString(digest);
} catch (NoSuchAlgorithmException ex) {
    throw new RuntimeException(
            "Can't send multipart upload. Can't create " + algorithm + " digest. " + ex.getMessage(), ex);
byte[]digest(byte[] bytes, String algorithmName)
Returns a hash of a set of bytes digested by an encryption algorithm.
try {
    return MessageDigest.getInstance(algorithmName).digest(bytes);
} catch (NoSuchAlgorithmException e) {
    return null;
byte[]digest(byte[] bytes, String txt)
Compute a MD5 hash from the text.
try {
    MessageDigest dig = MessageDigest.getInstance("MD5");
    if (bytes != null)
        dig.update(bytes);
    if (txt != null)
        dig.update(txt.getBytes("UTF-8"));
    return dig.digest();
} catch (Exception e) {
...
byte[]digest(byte[] data)
digest
try {
    MessageDigest d = MessageDigest.getInstance(DIGEST_ALGORITHM);
    d.update(data);
    return d.digest();
} catch (Exception ex) {
    throw new RuntimeException(ex);
Stringdigest(byte[] data, String algorithm)
digest
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    byte[] digest = md.digest(data);
    StringBuilder buf = new StringBuilder();
    for (byte b : digest) {
        buf.append(Integer.toHexString(0xF & (b >> 4)));
        buf.append(Integer.toHexString(0xF & (b)));
    return buf.toString();
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException(e);
byte[]digest(byte[] data, String algorithm)
digest
if (data == null || data.length <= 0) {
    return null;
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    md.update(data);
    return md.digest();
} catch (NoSuchAlgorithmException e) {
...
byte[]digest(byte[] input)
A synchronizer wrapper for the static digester, only access it through this utility method.
return s_digester.digest(input);
byte[]digest(byte[] input, final String algorithm)
Do digest on byte array with specified algorithm.
MessageDigest digest = MessageDigest.getInstance(algorithm);
digest.reset();
return digest.digest(input);