Skip to content

crypto ​

luau
local crypto = require("@lute/crypto")

WARNING

These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.

Summary ​

EntryDescription
SecretBoxA sealed message containing the encrypted ciphertext, nonce, and key.
digestComputes a cryptographic hash of message using the given hash algorithm. Returns the hash as a buffer.
password.hashHashes password using a slow, memory-hard algorithm suitable for password storage. Returns the hash as a buffer.
password.verifyVerifies that password matches the stored hash. Returns true if the password is correct.
secretbox.keygenGenerates a new random secret key for use with secretbox.seal.
secretbox.openDecrypts box and returns the original plaintext as a buffer.
secretbox.sealEncrypts message with key (or a freshly generated key if omitted). Returns a SecretBox.

Types ​

SecretBox ​

A sealed message containing the encrypted ciphertext, nonce, and key.

luau
type SecretBox = {
	read ciphertext: buffer,
	read nonce: buffer,
	read key: buffer,
}

Functions and Properties ​

crypto.digest ​

Computes a cryptographic hash of message using the given hash algorithm. Returns the hash as a buffer.

luau
(hash: Hash<any>, message: string | buffer) -> buffer

crypto.password.hash ​

Hashes password using a slow, memory-hard algorithm suitable for password storage. Returns the hash as a buffer.

luau
(password: string) -> buffer

crypto.password.verify ​

Verifies that password matches the stored hash. Returns true if the password is correct.

luau
(hash: buffer, password: string) -> boolean

crypto.secretbox.keygen ​

Generates a new random secret key for use with secretbox.seal.

luau
() -> buffer

crypto.secretbox.open ​

Decrypts box and returns the original plaintext as a buffer.

luau
(box: SecretBox) -> buffer

crypto.secretbox.seal ​

Encrypts message with key (or a freshly generated key if omitted). Returns a SecretBox.

luau
(message: string | buffer, key: buffer?) -> SecretBox