The org.apache.commons.codec.cli.Digest class provides a minimal command-line interface to compute message digests (hashes) for files, directories, or strings.
Usage Pattern
Run the class via the Java CLI using the following syntax:
java org.apache.commons.codec.cli.Digest [algorithm] [FILE|DIRECTORY|string] ...
Arguments
algorithm: The name of the digest algorithm (e.g., a name from MessageDigestAlgorithms or MessageDigest).- Use
ALL or * to output the digest for every known algorithm.
FILE|DIRECTORY|string: The target to digest.- If a file or directory is provided, the tool processes the file(s).
- If a directory is provided, it recursively processes all files within that directory.
- If the input is not a valid file or directory path, it is treated as a literal string to be digested.
- If no input is provided after the algorithm, the tool reads from standard input (stdin).
Output Format
The output follows the standard pattern: [algorithm] [hex-encoded-digest] [filename] (where the filename is omitted if reading from stdin or a raw string).
java org.apache.commons.codec.cli.Digest SHA-256 my_file.txt