Appearance
Crypto Module
This module provides various cryptographic utilities, including hashing, HMAC and key/token generation.
Table of Contents
- bcrypt
- sha256
- sha1
- md5
- hmac_sha1
- hmac_sha256
- key / genkey / createkey
- token / gentoken / genpass / genpassword
crypto.bcrypt()
Usage
- bcrypt(value): Generates bcrypt hash of the given value.
- bcrypt(value, hash): Verifies that the value matches the given bcrypt hash.
Example
javascript
crypto.bcrypt("password")
// → hashed string
crypto.bcrypt("password", hash)
// → true or falsecrypto.sha256()
Hashes a single value with SHA-256.
Usage
- sha256(value): Returns the SHA-256 digest as a byte array.
Example
javascript
crypto.sha256("hello")
// → byteArraycrypto.sha1()
Hashes a single value with SHA-1.
Usage
- sha1(value): Returns the SHA-1 digest as a byte array.
Example
javascript
crypto.sha1("hello")
// → [byte[]]crypto.md5()
Hashes a single value with MD5.
Usage
- md5(value): Returns the MD5 digest as a byte array.
Example
javascript
crypto.md5("hello")
// → [byte[]]crypto.hmac_sha1()
Computes HMAC using SHA-1.
Usage
- hmac_sha1(key, value): Returns HMAC-SHA1 digest.
Example
javascript
crypto.hmac_sha1("key", "message")
// → [byte[]]crypto.hmac_sha256()
Computes HMAC using SHA-256.
Usage
- hmac_sha256(key, value): Returns HMAC-SHA256 digest.
Example
javascript
crypto.hmac_sha256("key", "message")
// → [byte[]]key / genkey / createkey
Generates a random key of specified byte length.
Usage
- key(length): Returns a byte array of random bytes.
Constraints
- Length must be a number ≤ 65536.
Example
javascript
crypto.key(32)
// → [byte[]]token / gentoken / genpass / genpassword
Generates a random alphanumeric string token.
Usage
- token(length): Uses default character set.
- token(length, alphabet): Uses a custom set of characters.
Constraints
- Length ≤ 65536.
- Alphabet must have at least 2 unique characters.
Example
javascript
crypto.token(16)
// → "kF92jdla0xZ..."Default Alphabet (for Tokens)
If no custom alphabet is provided to token(), it uses:
QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890Notes
- All methods throw runtime exceptions if called with invalid argument counts or types.