Cryptographic Accelerator
The Cryptographic Accelerator is a peripheral that adds cryptographic functions and utilities that ComputerCraft may be too slow or incompatible to implement to.

Methods¶
The network name of the Cryptographic Accelerator peripheral is cryptographic_accelerator, you can wrap it via the peripheral functions like peripheral.wrap or peripheral.find.
Hashing¶
Note: hex arguments are by default true unless explicitly set.¶
md5(data: string, [hex: boolean]): stringHash data with theMD5algorithm.sha1(data: string, [hex: boolean]): stringHash data with theSHA1algorithm.sha256(data: string, [hex: boolean]): stringHash data with theSHA256algorithm.sha512(data: string, [hex: boolean]): stringHash data with theSHA512algorithm.hmacMd5(key: string, data: string, [hex: boolean]): stringHash data with theMD5algorithm and HMAC key.hmacSha1(key: string, data: string, [hex: boolean]): stringHash data with theSHA1algorithm and HMAC key.hmacSha256(key: string, data: string, [hex: boolean]): stringHash data with theSHA256algorithm and HMAC key.hmacSha512(key: string, data: string, [hex: boolean]): stringHash data with theSHA512algorithm and HMAC key.
BLAKE3 (v0.6.1+)¶
blake3(data: string, [hex: boolean], [mode: string], [param: string], [outputSize: number]): stringHash data with theBLAKE3algorithm.
Modes¶
hash: Hash data. Theparamargument is ignored.keyed: Hash data with a key, requiresparamargument to be a 32-bytes string key.derive: Hash data with a context string, requiresparamargument to be a string of any length.
Output Size¶
The BLAKE3 algorithm allows to set the output size of the digest (returned string). By default it is 32 bytes (256 bit).
The output size is limited up to 4096 bytes for ComputerCraft performance reasons.
Random¶
random(): numberGenerate a cryptographically secure random number.random(max: number): numberGenerate a cryptographically secure random number between 0 andmax(exclusive).random(min: number, max: number): numberGenerate a cryptographically secure random number betweenmin(inclusive) andmax(exclusive).randomBytes(length: number): stringGenerate a string composed of securely randomly generated bytes.
Encoding¶
encodeBase64(data: string): stringEncode a string to Base64.decodeBase64(data: string): stringDecode a Base64 string or return nil if input is invalid.
Symmetric Encryption¶
encryptAes(data: string, key: string, iv: string): stringEncrypt a string using AES algorithm with CBC.decryptAes(data: string, key: string, iv: string): stringDecrypt a string using AES algorithm with CBC.
Asymmetric Signing and Key Exchange¶
Note: Curve25519 (Elliptic Curve) algorithm is used in the following methods.¶
generatePrivateKey(): stringGenerate a new private key for Ed25519 and X25519.
Signing functions (Ed25519)¶
derivePublicKey(privateKey: string): stringDerive the Ed25519 public key from a private key.sign(message: string, privateKey: string): stringSign a message using a private key.verify(message: string, signature: string, publicKey: string): booleanVerify whether a message has been signed with the correct key pair.
Key Exchange functions (X25519)¶
deriveEcdhPublicKey(privateKey: string): stringDerive the X25519 public key from a private key.computeSharedSecret(privateKey: string, peerPublicKey: string): stringUse your private key and the peer's public key to compute the shared secret.
Compression (v0.6.0+)¶
deflate(data: string): stringCompress data using the DEFLATE compression algorithm.inflate(data: string): stringDecompress data using the DEFLATE compression algorithm.