Cryptography
zune.crypto
A library to do cryptographic operations in luau. Provides functions for hashing, aead, tls, and secure random number generation.
Functions
createHash
createHash(algorithm: export type CryptoHashAlgorithms =
| "sha1"
| "md5"
| "blake3"
| "sha224"
| "sha256"
| "sha384"
| "sha512"
| "sha3_224"
| "sha3_256"
| "sha3_384"
| "sha3_512"
| "blake2b128"
| "blake2b160"
| "blake2b256"
| "blake2b384"
| "blake2b512"
| "blake2s128"
| "blake2s160"
| "blake2s224"
| "blake2s256"CryptoHashAlgorithmsexport type CryptoHashAlgorithms =
| "sha1"
| "md5"
| "blake3"
| "sha224"
| "sha256"
| "sha384"
| "sha512"
| "sha3_224"
| "sha3_256"
| "sha3_384"
| "sha3_512"
| "blake2b128"
| "blake2b160"
| "blake2b256"
| "blake2b384"
| "blake2b512"
| "blake2s128"
| "blake2s160"
| "blake2s224"
| "blake2s256", secret: string?): CryptoHash
Parameters
algorithm: CryptoHashAlgorithms
secret: string?
Namespaces
password
FUNCTIONS
hash
password.hash(password: string | buffer, opts: type BcryptPasswordOptions = {
algorithm: "bcrypt"?,
cost: number?,
}
type Argon2PasswordOptions = {
algorithm: ("argon2d" | "argon2i" | "argon2id")?,
time_cost: number?,
memory_cost: number?,
threads: number?,
}
export type CryptoPasswordOptions = BcryptPasswordOptions | Argon2PasswordOptionsCryptoPasswordOptionstype BcryptPasswordOptions = {
algorithm: "bcrypt"?,
cost: number?,
}
type Argon2PasswordOptions = {
algorithm: ("argon2d" | "argon2i" | "argon2id")?,
time_cost: number?,
memory_cost: number?,
threads: number?,
}
export type CryptoPasswordOptions = BcryptPasswordOptions | Argon2PasswordOptions?): string
Parameters
password: string | buffer
- The password to hash.opts: CryptoPasswordOptions?
- The options for the password hashing.
Throws
- Crypto Error
- Memory Error
verify
password.verify(password: string | buffer, hash: string | buffer): boolean
Parameters
password: string | buffer
- The password to verify.hash: string | buffer
- The hash to verify against.
Throws
- Crypto Error
uuid
FUNCTIONS
v4
uuid.v4(): string
v7
uuid.v7(): string
random
Cryptographically secure random number generator.
FUNCTIONS
nextNumber
Generates a random number (f64).
If no arguments are provided, the function will generate a number between 0 and 1.
random.nextNumber(): number
random.nextNumber(min: number, max: number): number
Parameters
min: number?
- The minimum value (inclusive).max: number?
- The maximum value (inclusive).
Throws
- Range Error
nextInteger
Generates a random integer.
If no arguments are provided, the function will generate a number between the limits of a signed 32-bit integer.
random.nextInteger(): number
random.nextInteger(min: number, max: number): number
Parameters
min: number?
- The minimum value (inclusive).max: number?
- The maximum value (inclusive).
Throws
- Range Error
nextBoolean
Generates a random boolean.
random.nextBoolean(): boolean
fill
Write random bytes to the buffer.
random.fill(buffer: buffer, offset: number, length: number): ()
Parameters
buffer: buffer
- The buffer to write to.offset: number
- The offset to start writing at.length: number
- The number of bytes to write.
Throws
- Range Error
- Crypto Error
- Buffer Error
aead
NAMESPACES
aes_gcm
aead.aes_gcm.aes_gcm: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aes128Gcm: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aes256Gcm: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aes128Gcm: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aes256Gcm: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
aes_ocb
aead.aes_ocb.aes_ocb: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aes128Ocb: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aes256Ocb: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aes128Ocb: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aes256Ocb: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
aegis
aead.aegis.aegis: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aegis128X4: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X2: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128L: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X4: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X2: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X4_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X2_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128L_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X4_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X2_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
Aegis128X4: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X2: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128L: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X4: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X2: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X4_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128X2_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis128L_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X4_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256X2_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
Aegis256_256: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
chacha_poly
aead.chacha_poly.chacha_poly: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
ChaCha8Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
ChaCha12Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
ChaCha20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha8Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha12Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
ChaCha8Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
ChaCha12Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
ChaCha20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha8Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha12Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
XChaCha20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
salsa_poly
aead.salsa_poly.salsa_poly: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
XSalsa20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
XSalsa20Poly1305: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
isap
aead.isap.isap: <type EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
IsapA128A: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}tabletype EncryptedData = {
cipher: buffer,
tag: buffer,
}
type Input = string | buffer
<table> = {
IsapA128A: {
encrypt: (data: Input, key: Input, nonce: Input, ad: Input?) -> EncryptedData,
decrypt: (cipher: Input, tag: Input, key: Input, nonce: Input, ad: Input?) -> string,
},
}>
tls
FUNCTIONS
bundleFromSystem
tls.bundleFromSystem(): TlsCertBundle
Throws
- IO Error
- Tls Error
bundleFromFile
tls.bundleFromFile(file: string): TlsCertBundle
Parameters
file: string
- The file to load the bundle from.
Throws
- IO Error
keyPairFromFile
tls.keyPairFromFile(certFile: string, keyFile: string): TlsCertKeyPair
Parameters
certFile: string
- The certificate file.keyFile: string
- The key file.
Throws
- IO Error
- Tls Error
setupClient
tls.setupClient(socket: NetworkSocket, config: -- references:
-- (1) TlsCertBundle
export type CryptoTlsClientConfig = {
host: string,
ca: TlsCertBundle,
}CryptoTlsClientConfig-- references:
-- (1) TlsCertBundle
export type CryptoTlsClientConfig = {
host: string,
ca: TlsCertBundle,
}): ()
Parameters
socket: NetworkSocket
- The socket to setup the client on.config: CryptoTlsClientConfig
- The configuration for the client.host: string
- The host.ca: TlsCertBundle
- The CA bundle to use for verification.
Throws
- Tls Error
- Memory Error
setupServer
tls.setupServer(socket: NetworkSocket, config: -- references:
-- (1) TlsCertKeyPair
export type CryptoTlsServerConfig = {
auth: TlsCertKeyPair,
}CryptoTlsServerConfig-- references:
-- (1) TlsCertKeyPair
export type CryptoTlsServerConfig = {
auth: TlsCertKeyPair,
}): ()
Parameters
socket: NetworkSocket
- The socket to setup the server on.config: CryptoTlsServerConfig
- The configuration for the server.auth: TlsCertKeyPair
- The certificate and key pair to use for the server.
Throws
- Tls Error
- Memory Error
Last updated on