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(MessageDigest digest, InputStream data)
Read through an InputStream and returns the digest for the data
byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
while (read > -1) {
    digest.update(buffer, 0, read);
    read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
return digest.digest();
Stringdigest(MessageDigest method, File f)
digest
byte[] b = new byte[4096];
FileInputStream fs = new FileInputStream(f);
while (true) {
    int readBytes = fs.read(b);
    if (readBytes < 0)
        break;
    method.update(b, 0, readBytes);
byte[] digest = method.digest();
return toHexString(digest);
Stringdigest(Serializable object)
digest
assert object != null;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
    try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream)) {
        objectOutputStream.writeObject(object);
        return createChecksumHex(outputStream.toByteArray());
byte[]digest(String alg, byte[] plainByte)
digest
MessageDigest md = MessageDigest.getInstance(alg);
md.update(plainByte);
return md.digest();
byte[]digest(String algorithm, byte[] bytes)
digest
return getDigest(algorithm).digest(bytes);
byte[]digest(String algorithm, byte[] data)
Hash a given string
MessageDigest digest;
try {
    digest = MessageDigest.getInstance(algorithm);
    byte[] hash = digest.digest(data);
    return hash;
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return null;
...
byte[]digest(String algorithm, String data)
digest
MessageDigest digest;
try {
    digest = MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
return digest.digest(data.getBytes());
Stringdigest(String aValue)
digest
aValue = aValue.trim();
byte[] value;
try {
    value = aValue.getBytes(encodingCharset);
} catch (UnsupportedEncodingException e) {
    value = aValue.getBytes();
MessageDigest md = null;
...
Stringdigest(String base)
digest
MessageDigest digest = defaultMessageDigest();
byte[] hash = digest.digest(base.getBytes(StandardCharsets.UTF_8));
return bytesToHexString(hash);
byte[]digest(String digest, byte[] data)
Calculates the SHA digest and returns the value as a 16 element byte[] .
return getDigest(digest).digest(data);