Modules@robinpath/hash
hash

@robinpath/hash

0.1.3Node.jsPublic

Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting

Hash

Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting

Package: @robinpath/hash | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the hash module when you need to:

  • Compute MD5 hash of a string -- Use hash.md5 to perform this operation
  • Compute SHA-1 hash of a string -- Use hash.sha1 to perform this operation
  • Compute SHA-256 hash of a string -- Use hash.sha256 to perform this operation
  • Compute SHA-512 hash of a string -- Use hash.sha512 to perform this operation
  • Compute SHA-3 hash of a string -- Use hash.sha3 to perform this operation

Quick Reference

FunctionDescriptionReturns
md5Compute MD5 hash of a stringobject
sha1Compute SHA-1 hash of a stringobject
sha256Compute SHA-256 hash of a stringobject
sha512Compute SHA-512 hash of a stringobject
sha3Compute SHA-3 hash of a stringobject
hmacCompute HMAC of a string with a secret keyobject
hashFileCompute the hash of a file's contentsobject
hashStreamCompute a hash from an array of data chunks (simulates stream hashing)object
crc32Compute CRC32 checksum of a stringobject
checksumVerify that a string matches an expected hashobject
compareTiming-safe comparison of two strings to prevent timing attacksobject
uuid5Generate a deterministic UUID v5 from a name and namespaceobject
randomBytesGenerate cryptographically secure random bytesobject
randomHexGenerate a random hexadecimal string of specified lengthobject
randomBase64Generate a random Base64-encoded stringobject
fingerprintGenerate a content fingerprint combining MD5 and SHA-256 hashesobject

Functions

md5

Compute MD5 hash of a string

Module: hash | Returns: object -- API response.

hash.md5
ParameterTypeRequiredDescription
inputstringYesThe string to hash
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

sha1

Compute SHA-1 hash of a string

Module: hash | Returns: object -- API response.

hash.sha1
ParameterTypeRequiredDescription
inputstringYesThe string to hash
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

sha256

Compute SHA-256 hash of a string

Module: hash | Returns: object -- API response.

hash.sha256
ParameterTypeRequiredDescription
inputstringYesThe string to hash
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

sha512

Compute SHA-512 hash of a string

Module: hash | Returns: object -- API response.

hash.sha512
ParameterTypeRequiredDescription
inputstringYesThe string to hash
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

sha3

Compute SHA-3 hash of a string

Module: hash | Returns: object -- API response.

hash.sha3
ParameterTypeRequiredDescription
inputstringYesThe string to hash
bitsnumberNoHash bit length: 224, 256 (default), 384, or 512
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

hmac

Compute HMAC of a string with a secret key

Module: hash | Returns: object -- API response.

hash.hmac
ParameterTypeRequiredDescription
inputstringYesThe string to hash
keystringYesThe secret key
algorithmstringNoHash algorithm (default: 'sha256')
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

hashFile

Compute the hash of a file's contents

Module: hash | Returns: object -- API response.

hash.hashFile
ParameterTypeRequiredDescription
filePathstringYesAbsolute path to the file
algorithmstringNoHash algorithm (default: 'sha256')
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

hashStream

Compute a hash from an array of data chunks (simulates stream hashing)

Module: hash | Returns: object -- API response.

hash.hashStream
ParameterTypeRequiredDescription
chunksarrayYesArray of strings or buffers to hash
algorithmstringNoHash algorithm (default: 'sha256')
encodingstringNoOutput encoding: 'hex' (default) or 'base64'

crc32

Compute CRC32 checksum of a string

Module: hash | Returns: object -- API response.

hash.crc32
ParameterTypeRequiredDescription
inputstringYesThe string to checksum
asHexbooleanNoReturn as hex string instead of number (default: false)

checksum

Verify that a string matches an expected hash

Module: hash | Returns: object -- API response.

hash.checksum
ParameterTypeRequiredDescription
inputstringYesThe string to verify
expectedHashstringYesThe expected hash value
algorithmstringNoHash algorithm (default: 'sha256')

compare

Timing-safe comparison of two strings to prevent timing attacks

Module: hash | Returns: object -- API response.

hash.compare
ParameterTypeRequiredDescription
astringYesFirst string
bstringYesSecond string

uuid5

Generate a deterministic UUID v5 from a name and namespace

Module: hash | Returns: object -- API response.

hash.uuid5
ParameterTypeRequiredDescription
namestringYesThe name to generate UUID from
namespacestringNoNamespace UUID (default: DNS namespace)

randomBytes

Generate cryptographically secure random bytes

Module: hash | Returns: object -- API response.

hash.randomBytes
ParameterTypeRequiredDescription
sizenumberNoNumber of bytes (default: 32)
encodingstringNoOutput encoding: 'hex' (default), 'base64', 'buffer'

randomHex

Generate a random hexadecimal string of specified length

Module: hash | Returns: object -- API response.

hash.randomHex
ParameterTypeRequiredDescription
lengthnumberNoLength of hex string (default: 32)

randomBase64

Generate a random Base64-encoded string

Module: hash | Returns: object -- API response.

hash.randomBase64
ParameterTypeRequiredDescription
byteCountnumberNoNumber of random bytes (default: 32)
urlSafebooleanNoUse URL-safe Base64 (default: false)

fingerprint

Generate a content fingerprint combining MD5 and SHA-256 hashes

Module: hash | Returns: object -- API response.

hash.fingerprint
ParameterTypeRequiredDescription
inputstringYesThe content to fingerprint

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "Md5 and validate result"
do
  set $result as hash.md5
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Hash workflow

Chain multiple hash operations together.

@desc "Md5, sha1, and more"
do
  set $r_md5 as hash.md5
  set $r_sha1 as hash.sha1
  set $r_sha256 as hash.sha256
  print "All operations complete"
enddo

2. Safe md5 with validation

Check results before proceeding.

@desc "Md5 and validate result"
do
  set $result as hash.md5
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (3)

VersionTagPublished
0.1.3latest21 days ago
0.1.221 days ago
0.1.11 months ago
Install
$ robinpath add @robinpath/hash

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.3
LicenseMIT
Unpacked Size10.7 KB
Versions3
Weekly Downloads28
Total Downloads28
Stars0
Last Publish21 days ago
Created1 months ago

Keywords

Category

utilities