Docs
API Reference
Crypto

Cryptography

ℹ️
Page is being worked on.

Namespaces

  1. hash
  2. hmac
  3. password
  4. random
  5. aes

hash

Namespaces

  1. hash.sha2
  2. hash.sha3
  3. hash.blake2

Functions

  1. hash.md5
  2. hash.sha1
  3. hash.blake3

hash.md5

crypto.hash.md5(str: string): string

Hashes a string using the MD5 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha1

crypto.hash.sha1(str: string): string

Hashes a string using the Sha1 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake3

crypto.hash.blake3(str: string): string

Hashes a string using the Blake3 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha2

Functions

  1. hash.sha2.sha224
  2. hash.sha2.sha256
  3. hash.sha2.sha384
  4. hash.sha2.sha512

hash.sha2.sha224

crypto.hash.sha2.sha224(str: string): string

Hashes a string using the Sha2-Sha224 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha2.sha256

crypto.hash.sha2.sha256(str: string): string

Hashes a string using the Sha2-Sha256 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha2.sha384

crypto.hash.sha2.sha384(str: string): string

Hashes a string using the Sha2-Sha384 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha2.sha512

crypto.hash.sha2.sha512(str: string): string

Hashes a string using the Sha2-Sha512 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha3

Functions

  1. hash.sha3.sha3_224
  2. hash.sha3.sha3_256
  3. hash.sha3.sha3_384
  4. hash.sha3.sha3_512

hash.sha3.sha3_224

crypto.hash.sha3.sha3_224(str: string): string

Hashes a string using the Sha3-Sha3_224 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha3.sha3_256

crypto.hash.sha3.sha3_256(str: string): string

Hashes a string using the Sha3-Sha3_256 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha3.sha3_384

crypto.hash.sha3.sha3_384(str: string): string

Hashes a string using the Sha3-Sha3_384 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.sha3.sha3_512

crypto.hash.sha3.sha3_512(str: string): string

Hashes a string using the Sha3-Sha3_512 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2

Functions

  1. hash.blake2.b128
  2. hash.blake2.b160
  3. hash.blake2.b256
  4. hash.blake2.b512
  5. hash.blake2.s128
  6. hash.blake2.s160
  7. hash.blake2.s224
  8. hash.blake2.s256

hash.blake2.b128

crypto.hash.blake2.b128(str: string): string

Hashes a string using the Blake2-B128 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.b160

crypto.hash.blake2.b160(str: string): string

Hashes a string using the Blake2-B160 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.b256

crypto.hash.blake2.b256(str: string): string

Hashes a string using the Blake2-B256 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.b512

crypto.hash.blake2.b512(str: string): string

Hashes a string using the Blake2-B512 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.s128

crypto.hash.blake2.s128(str: string): string

Hashes a string using the Blake2-S128 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.s160

crypto.hash.blake2.s160(str: string): string

Hashes a string using the Blake2-S160 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.s224

crypto.hash.blake2.s224(str: string): string

Hashes a string using the Blake2-S224 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hash.blake2.s256

crypto.hash.blake2.s256(str: string): string

Hashes a string using the Blake2-S256 algorithm.

Parameters
  • str: string - The string to hash.
Returns
  • string - The hashed string in hex.

hmac

Namespaces

  1. hmac.sha2
  2. hmac.sha3
  3. hmac.blake2

Functions

  1. hmac.md5
  2. hmac.sha1
  3. hmac.blake3

hmac.md5

crypto.hmac.md5(str: string, key: string): string

Hashes a string using the MD5 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha1

crypto.hmac.sha1(str: string, key: string): string

Hashes a string using the Sha1 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake3

crypto.hmac.blake3(str: string, key: string): string

Hashes a string using the Blake3 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha2

Functions

  1. hmac.sha2.sha224
  2. hmac.sha2.sha256
  3. hmac.sha2.sha384
  4. hmac.sha2.sha512

hmac.sha2.sha224

crypto.hmac.sha2.sha224(str: string, key: string): string

Hashes a string using the Sha2-Sha224 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha2.sha256

crypto.hmac.sha2.sha256(str: string, key: string): string

Hashes a string using the Sha2-Sha256 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha2.sha384

crypto.hmac.sha2.sha384(str: string, key: string): string

Hashes a string using the Sha2-Sha384 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha2.sha512

crypto.hmac.sha2.sha512(str: string, key: string): string

Hashes a string using the Sha2-Sha512 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha3

Functions

  1. hmac.sha3.sha3_224
  2. hmac.sha3.sha3_256
  3. hmac.sha3.sha3_384
  4. hmac.sha3.sha3_512

hmac.sha3.sha3_224

crypto.hmac.sha3.sha3_224(str: string, key: string): string

Hashes a string using the Sha3-Sha3_224 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha3.sha3_256

crypto.hmac.sha3.sha3_256(str: string, key: string): string

Hashes a string using the Sha3-Sha3_256 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha3.sha3_384

crypto.hmac.sha3.sha3_384(str: string, key: string): string

Hashes a string using the Sha3-Sha3_384 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.sha3.sha3_512

crypto.hmac.sha3.sha3_512(str: string, key: string): string

Hashes a string using the Sha3-Sha3_512 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2

Functions

  1. hmac.blake2.b128
  2. hmac.blake2.b160
  3. hmac.blake2.b256
  4. hmac.blake2.b512
  5. hmac.blake2.s128
  6. hmac.blake2.s160
  7. hmac.blake2.s224
  8. hmac.blake2.s256

hmac.blake2.b128

crypto.hmac.blake2.b128(str: string, key: string): string

Hashes a string using the Blake2-B128 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.b160

crypto.hmac.blake2.b160(str: string, key: string): string

Hashes a string using the Blake2-B160 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.b256

crypto.hmac.blake2.b256(str: string, key: string): string

Hashes a string using the Blake2-B256 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.b512

crypto.hmac.blake2.b512(str: string, key: string): string

Hashes a string using the Blake2-B512 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.s128

crypto.hmac.blake2.s128(str: string, key: string): string

Hashes a string using the Blake2-S128 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.s160

crypto.hmac.blake2.s160(str: string, key: string): string

Hashes a string using the Blake2-S160 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.s224

crypto.hmac.blake2.s224(str: string, key: string): string

Hashes a string using the Blake2-S224 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

hmac.blake2.s256

crypto.hmac.blake2.s256(str: string, key: string): string

Hashes a string using the Blake2-S256 algorithm.

Parameters
  • str: string - The string to hash.
  • key: string - The key to hash with.
Returns
  • string - The hashed string in hex.

password

Functions

  1. password.hash
  2. password.verify

password.hash

crypto.password.hash(str: string, options: PasswordOptions?): string

Hashes a string using the specified algorithm in options, or defaults to argon2d.

Parameters
  • str: string - The string to hash.
  • options:PasswordOptions? - The options for the hashing.
Returns
  • string - The hashed string in hex.

password.verify

crypto.password.verify(str: string, hash: string): boolean

Verifies a string against a hash using the algorithm encoded in the hash.

Parameters
  • str: string - The string to verify.
  • hash: string - The hash to verify against.
Returns
  • boolean - Whether the string matches the hash.

random

Cryptographically secure pseudorandom number generator (CSPRNG).

Functions

  1. random.nextNumber
  2. random.nextInteger
  3. random.nextBoolean
  4. random.fill

random.nextNumber

crypto.random.nextNumber(): number
crypto.random.nextNumber(min: number, max: number): number

Generates a random number (f64), if no arguments are provided, it will generate a number between 0 and 1.

Parameters
  • min: number? - The minimum number to generate.
  • max: number? - The maximum number to generate.
Returns
  • number - The generated number.

random.nextInteger

crypto.random.nextInteger(): number
crypto.random.nextInteger(min: number, max: number): number

Generates a random integer (i32), if no arguments are provided,

it will generate a number between the limits of a signed 32-bit integer.

Parameters
  • min: number? - The minimum number to generate.
  • max: number? - The maximum number to generate.
Returns
  • number - The generated number.

random.nextBoolean

crypto.random.nextBoolean(): boolean

Generates a random boolean.

Returns
  • boolean - The generated boolean.

random.fill

crypto.random.fill(buffer: buffer, offset: number, length: number): ()

Writes random bytes to the buffer.

Parameters
  • buffer: buffer - The buffer to write to.
  • offset: number - The offset to start writing at.
  • length: number - The number of bytes to write.

aes

Functions

  1. aes.aes128
  2. aes.aes256

aes.aes128

Functions

  1. aes.aes128.encrypt
  2. aes.aes128.decrypt

aes.aes128.encrypt

crypto.aes.aes128.encrypt(data: string | buffer, key: string | buffer, nonce: string | buffer): EncryptedAes

Encrypts a string or buffer using the AES-128 algorithm.

Parameters
  • data: string | buffer - The data to encrypt.
  • key: string | buffer - The key to encrypt with.
  • nonce: string | buffer - The nonce to encrypt with.
Returns

aes.aes128.decrypt

crypto.aes.aes128.decrypt(cipher: string | buffer, tag: string | buffer, key: string | buffer, nonce: string | buffer): string

Decrypts a string or buffer using the AES-128 algorithm.

Parameters
  • cipher: string | buffer - The data to decrypt.
  • tag: string | buffer - The tag to decrypt with.
  • key: string | buffer - The key to decrypt with.
  • nonce: string | buffer - The nonce to decrypt with.
Returns
  • string - The decrypted data.

aes.aes256

Functions

  1. aes.aes256.encrypt
  2. aes.aes256.decrypt

aes.aes256.encrypt

crypto.aes.aes256.encrypt(data: string | buffer, key: string | buffer, nonce: string | buffer): EncryptedAes

Encrypts a string or buffer using the AES-256 algorithm.

Parameters
  • data: string | buffer - The data to encrypt.
  • key: string | buffer - The key to encrypt with.
  • nonce: string | buffer - The nonce to encrypt with.
Returns

aes.aes256.decrypt

crypto.aes.aes256.decrypt(cipher: string | buffer, tag: string | buffer, key: string | buffer, nonce: string | buffer): string

Decrypts a string or buffer using the AES-256 algorithm.

Parameters
  • cipher: string | buffer - The data to decrypt.
  • tag: string | buffer - The tag to decrypt with.
  • key: string | buffer - The key to decrypt with.
  • nonce: string | buffer - The nonce to decrypt with.
Returns
  • string - The decrypted data.

Types

BcryptPasswordOptions

type BcryptPasswordOptions = {
    --- Default: "argon2d"
    algorithm: "bcrypt"?,
    --[[
        Default: 4
        
        Only between 4 and 31
    ]]
    cost: number?,
}

Argon2PasswordOptions

type Argon2PasswordOptions = {
    --- Default: "argon2d"
    algorithm: ("argon2d" | "argon2i" | "argon2id")?,
    --- Default: 2
    timeCost: number?,
    --- Default: 65536
    memoryCost: number?,
}

PasswordOptions

type PasswordOptions = BcryptPasswordOptions | Argon2PasswordOptions

EncryptedAes

type EncryptedAes = {
    cipher : string,
    tag : string,
}