Skip to main content

Checksum

The Checksum object provides methods to compute various cryptographic hash checksums for a given input string, binary data, or file.

Methods

Checksum.MD5(input)

Computes the MD5 checksum for the given input.

  • Input: A string or Uint8Array (binary data).
  • Output: Returns the MD5 checksum as a hexadecimal string.

Example Usage:

const checksum = Checksum.MD5("Hello World");
console.log(checksum); // Output: MD5 checksum of "Hello World"

Checksum.SHA1(input)

Computes the SHA-1 checksum for the given input.

  • Input: A string or Uint8Array (binary data).
  • Output: Returns the SHA-1 checksum as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA1("Hello World");
console.log(checksum); // Output: SHA-1 checksum of "Hello World"

Checksum.SHA256(input)

Computes the SHA-256 checksum for the given input.

  • Input: A string or Uint8Array (binary data).
  • Output: Returns the SHA-256 checksum as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA256("Hello World");
console.log(checksum); // Output: SHA-256 checksum of "Hello World"

Checksum.SHA512(input)

Computes the SHA-512 checksum for the given input.

  • Input: A string or Uint8Array (binary data).
  • Output: Returns the SHA-512 checksum as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA512("Hello World");
console.log(checksum); // Output: SHA-512 checksum of "Hello World"

File-Based Methods

These methods compute the checksum of a file’s binary data.

Checksum.MD5File(filename)

Computes the MD5 checksum for a given file.

  • Input: A file path as a string.
  • Output: Returns the MD5 checksum of the file’s contents as a hexadecimal string.

Example Usage:

const checksum = Checksum.MD5File("path/to/file.txt");
console.log(checksum); // Output: MD5 checksum of the file

Checksum.SHA1File(filename)

Computes the SHA-1 checksum for a given file.

  • Input: A file path as a string.
  • Output: Returns the SHA-1 checksum of the file’s contents as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA1File("path/to/file.txt");
console.log(checksum); // Output: SHA-1 checksum of the file

Checksum.SHA256File(filename)

Computes the SHA-256 checksum for a given file.

  • Input: A file path as a string.
  • Output: Returns the SHA-256 checksum of the file’s contents as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA256File("path/to/file.txt");
console.log(checksum); // Output: SHA-256 checksum of the file

Checksum.SHA512File(filename)

Computes the SHA-512 checksum for a given file.

  • Input: A file path as a string.
  • Output: Returns the SHA-512 checksum of the file’s contents as a hexadecimal string.

Example Usage:

const checksum = Checksum.SHA512File("path/to/file.txt");
console.log(checksum); // Output: SHA-512 checksum of the file