Cryptography
Namespaces
hash
Namespaces
Functions
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
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
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
- hash.blake2.b128
- hash.blake2.b160
- hash.blake2.b256
- hash.blake2.b512
- hash.blake2.s128
- hash.blake2.s160
- hash.blake2.s224
- 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
Functions
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
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
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
- hmac.blake2.b128
- hmac.blake2.b160
- hmac.blake2.b256
- hmac.blake2.b512
- hmac.blake2.s128
- hmac.blake2.s160
- hmac.blake2.s224
- 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
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
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
aes.aes128
Functions
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
EncryptedAes
- The encrypted data.
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
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
EncryptedAes
- The encrypted data.
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,
}