Class Sha256

java.lang.Object
network.ike.plugin.scaffold.Sha256

public final class Sha256 extends Object
SHA-256 hash utility for scaffold checksums.

Produces values in the canonical lockfile form "sha256:" + lowercase-hex-digest. All scaffold lockfile and manifest hashes must flow through this class so the algorithm label stays consistent.

Hashes are computed over the raw byte content of the file or string. Consumers that need line-ending normalisation must do so before calling this class.

  • Field Details

  • Method Details

    • of

      public static String of(byte[] data)
      Hash a byte array.
      Parameters:
      data - the bytes to hash; null is treated as empty
      Returns:
      "sha256:" + hex-digest
    • of

      public static String of(String text)
      Hash a string using UTF-8 encoding.
      Parameters:
      text - the string to hash; null is treated as empty
      Returns:
      "sha256:" + hex-digest
    • ofFile

      public static String ofFile(Path path)
      Hash the bytes of a file, streaming so large files don't load into memory all at once.
      Parameters:
      path - existing readable file
      Returns:
      "sha256:" + hex-digest
      Throws:
      ScaffoldException - if the file cannot be read
    • matches

      public static boolean matches(Path path, String expected)
      Compare a known hash to the current hash of a file.
      Parameters:
      path - existing readable file
      expected - hash string in the form "sha256:" + hex-digest; null returns false
      Returns:
      true iff the file's current hash equals expected