Java SE API

MessageDigest.digest()

Finish a digest of bytes and reset the digest state. Not authentication.

Formal Syntax & Structure

java syntaxjava
byte[] digest(byte[] input)

Working Example

Example Snippetjava
import java.io.*;import java.nio.charset.StandardCharsets;import java.security.*;import java.util.*;import javax.crypto.*;import javax.crypto.spec.GCMParameterSpec;import javax.net.ssl.*;public class Main {
    public static void main(String[] args) throws Exception {        byte[] token = new byte[32];        new SecureRandom().nextBytes(token);        System.out.println(token.length);        byte[] digest = MessageDigest.getInstance("SHA-256").digest("abc".getBytes(StandardCharsets.UTF_8));        System.out.println(HexFormat.of().formatHex(digest));    }}
Java Reference