Skip to content

Cryptographic Accelerator

Alessandro Proto edited this page Jul 12, 2026 · 7 revisions

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

Cryptographic Accelerator

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]): string Hash data with the MD5 algorithm.
  • sha1(data: string, [hex: boolean]): string Hash data with the SHA1 algorithm.
  • sha256(data: string, [hex: boolean]): string Hash data with the SHA256 algorithm.
  • sha512(data: string, [hex: boolean]): string Hash data with the SHA512 algorithm.
  • hmacMd5(key: string, data: string, [hex: boolean]): string Hash data with the MD5 algorithm and HMAC key.
  • hmacSha1(key: string, data: string, [hex: boolean]): string Hash data with the SHA1 algorithm and HMAC key.
  • hmacSha256(key: string, data: string, [hex: boolean]): string Hash data with the SHA256 algorithm and HMAC key.
  • hmacSha512(key: string, data: string, [hex: boolean]): string Hash data with the SHA512 algorithm and HMAC key.

Random

  • random(): number Generate a cryptographically secure random number.
  • random(max: number): number Generate a cryptographically secure random number between 0 and max (exclusive).
  • random(min: number, max: number): number Generate a cryptographically secure random number between min (inclusive) and max (exclusive).
  • randomBytes(length: number): string Generate a string composed of securely randomly generated bytes.

Encoding

  • encodeBase64(data: string): string Encode a string to Base64.
  • decodeBase64(data: string): string Decode a Base64 string.

Symmetric Encryption

  • encryptAes(data: string, key: string, iv: string): string Encrypt a string using AES algorithm with CBC.
  • decryptAes(data: string, key: string, iv: string): string Decrypt a string using AES algorithm with CBC.

Asymmetric Signing and Key Exchange

Note: Curve25519 (Elliptic Curve) algorithm is used in the following methods.

  • generatePrivateKey(): string Generate a new private key for Ed25519 and X25519.

Signing functions (Ed25519)

  • derivePublicKey(privateKey: string): string Derive the Ed25519 public key from a private key.
  • sign(message: string, privateKey: string): string Sign a message using a private key.
  • verify(message: string, signature: string, publicKey: string): boolean Verify whether a message has been signed with the correct key pair.

Key Exchange functions (X25519)

  • deriveEcdhPublicKey(privateKey: string): string Derive the X25519 public key from a private key.
  • computeSharedSecret(privateKey: string, peerPublicKey: string): string Use your private key and the peer's public key to compute the shared secret.

Compression

  • deflate(data: string): string Compress data using the DEFLATE compression algorithm.
  • inflate(data: string): string Decompress data using the DEFLATE compression algorithm.

Clone this wiki locally