Apache Commons Codec

repository·master·Indexed 19 days ago

https://github.com/apache/commons-codec

A Java library providing encoders and decoders for common formats including Base16, Base32, Base64, and Hex, as well as message digests and phonetic encoding utilities. Includes a Digest CLI for computing hashes of files, directories, or strings.

Tokens
725
Snippets
3
Records
5
Agent score
17%

What's inside Apache Commons Codec

  1. Overview of Apache Commons Codec

    master

    Apache Commons Codec is a library providing encoders and decoders for various data formats. It is designed to handle common encoding tasks and phonetic utilities in Java applications.

    Key features include support for:

    • Base formats: Base16, Base32, and Base64.
    • Digests: Message digests (hashing).
    • Hexadecimal: Hex encoding and decoding.
    • Phonetic encoding: Utilities for phonetic matching and encoding.
  2. Add Apache Commons Codec to a Maven project

    master

    To use Apache Commons Codec in your Java project, add the following dependency to your pom.xml file. Ensure you use the latest version available in the central Maven repositories.

    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
      <version>1.22.1</version>
    </dependency>
  3. Build Apache Commons Codec from source

    master

    To build the project from the source code, you need a Java JDK and Apache Maven installed. The specific required Java version is defined in the pom.xml under the maven.compiler.source property.

    To run the default Maven goal (which executes all tests and checks), run the following command from the root of the repository:

    mvn
  4. Digest CLI algorithm options

    master

    When using the org.apache.commons.codec.cli.Digest command, you can specify which algorithms to use via the first argument:

    • Specific Algorithm: Provide a single algorithm name (e.g., MD5, SHA-1, SHA-256). The tool is case-insensitive for these names.
    • All Algorithms: Use ALL or * to compute and display digests for all available algorithms supported by the environment.
  5. Use the Digest CLI to compute message digests

    master

    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