Modules@robinpath/crypto
crypto

@robinpath/crypto

0.1.1Node.jsPublic

Hashing, HMAC, and encoding/decoding utilities (MD5, SHA, Base64, Hex, URL)

Crypto

Hashing, HMAC, and encoding/decoding utilities (MD5, SHA, Base64, Hex, URL)

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

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the crypto module when you need to:

  • Compute the MD5 hash of a string -- Use crypto.md5 to perform this operation
  • Compute the SHA-1 hash of a string -- Use crypto.sha1 to perform this operation
  • Compute the SHA-256 hash of a string -- Use crypto.sha256 to perform this operation
  • Compute the SHA-512 hash of a string -- Use crypto.sha512 to perform this operation
  • Compute an HMAC digest using the specified algorithm and secret key -- Use crypto.hmac to perform this operation

Quick Reference

FunctionDescriptionReturns
md5Compute the MD5 hash of a stringThe MD5 hex digest
sha1Compute the SHA-1 hash of a stringThe SHA-1 hex digest
sha256Compute the SHA-256 hash of a stringThe SHA-256 hex digest
sha512Compute the SHA-512 hash of a stringThe SHA-512 hex digest
hmacCompute an HMAC digest using the specified algorithm and secret keyThe HMAC hex digest
base64EncodeEncode a string to Base64The Base64-encoded string
base64DecodeDecode a Base64 string back to plain textThe decoded plain-text string
hexEncodeEncode a string to its hexadecimal representationThe hex-encoded string
hexDecodeDecode a hexadecimal string back to plain textThe decoded plain-text string
urlEncodePercent-encode a string for use in a URLThe URL-encoded string
urlDecodeDecode a percent-encoded URL string back to plain textThe decoded plain-text string

Functions

md5

Compute the MD5 hash of a string

Module: crypto | Returns: string -- The MD5 hex digest

crypto.md5 "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to hash

sha1

Compute the SHA-1 hash of a string

Module: crypto | Returns: string -- The SHA-1 hex digest

crypto.sha1 "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to hash

sha256

Compute the SHA-256 hash of a string

Module: crypto | Returns: string -- The SHA-256 hex digest

crypto.sha256 "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to hash

sha512

Compute the SHA-512 hash of a string

Module: crypto | Returns: string -- The SHA-512 hex digest

crypto.sha512 "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to hash

hmac

Compute an HMAC digest using the specified algorithm and secret key

Module: crypto | Returns: string -- The HMAC hex digest

crypto.hmac "sha256" "message" "secret"
ParameterTypeRequiredDescription
algorithmstringYesHash algorithm to use (e.g. sha256, sha512, md5)
messagestringYesThe message to authenticate
keystringYesThe secret key

base64Encode

Encode a string to Base64

Module: crypto | Returns: string -- The Base64-encoded string

crypto.base64Encode "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to encode

base64Decode

Decode a Base64 string back to plain text

Module: crypto | Returns: string -- The decoded plain-text string

crypto.base64Decode "aGVsbG8="
ParameterTypeRequiredDescription
inputstringYesThe Base64-encoded string to decode

hexEncode

Encode a string to its hexadecimal representation

Module: crypto | Returns: string -- The hex-encoded string

crypto.hexEncode "hello"
ParameterTypeRequiredDescription
inputstringYesThe string to encode

hexDecode

Decode a hexadecimal string back to plain text

Module: crypto | Returns: string -- The decoded plain-text string

crypto.hexDecode "68656c6c6f"
ParameterTypeRequiredDescription
inputstringYesThe hex-encoded string to decode

urlEncode

Percent-encode a string for use in a URL

Module: crypto | Returns: string -- The URL-encoded string

crypto.urlEncode "hello world"
ParameterTypeRequiredDescription
inputstringYesThe string to URL-encode

urlDecode

Decode a percent-encoded URL string back to plain text

Module: crypto | Returns: string -- The decoded plain-text string

crypto.urlDecode "hello%20world"
ParameterTypeRequiredDescription
inputstringYesThe URL-encoded string to decode

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 crypto.md5 "hello"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Crypto workflow

Chain multiple crypto operations together.

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

2. Safe md5 with validation

Check results before proceeding.

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

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/crypto

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.6 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities