This filename is legacy. The real Lua component name is data.
The data card provides hashing, encoding, compression, encryption, random generation, and elliptic-curve key operations. Available callbacks depend on the card tier.
- Repository:
opencomputers - Actual Lua component name:
data - Backing implementation:
li.cil.oc.server.component.DataCard - Typical hosts: machines or devices fitted with a data card
getLimitencode64decode64deflateinflatecrc32md5sha256decodeNBT
Adds:
- HMAC support for
md5 - HMAC support for
sha256 encryptdecryptrandom
Adds:
generateKeyPairdeserializeKeyecdhecdsa
Many callbacks return raw binary data, not printable text.
Typical examples:
- hashes
- AES ciphertext
- random bytes
- serialized keys
- ECDSA signatures
If you need text-safe transport or storage, encode the result with encode64().
getLimit() returns the hard maximum input size accepted by the card's data-processing callbacks.
- If the first binary/string argument exceeds that limit, the callback throws
data size limit exceeded. - Large inputs above the soft limit also make the computer pause for a configured timeout.
All callbacks consume connector energy.
- If the host has insufficient energy buffer, the callback fails with
not enough energy.
- Syntax:
data.getLimit() - Returns:
number - Purpose: Returns the hard maximum number of bytes accepted by the card's byte-processing callbacks.
- Syntax:
data.encode64(bytes) - Parameters:
bytes:string: raw binary or text data.
- Returns:
string - Purpose: Encodes the input using Base64.
- Syntax:
data.decode64(text) - Parameters:
text:string: Base64 text.
- Returns:
string - Purpose: Decodes Base64 input back into raw bytes.
- Syntax:
data.deflate(bytes) - Parameters:
bytes:string: raw input data.
- Returns:
string - Purpose: Compresses the input using the deflate format.
- Syntax:
data.inflate(bytes) - Parameters:
bytes:string: deflated binary data.
- Returns:
string - Purpose: Decompresses deflated binary data.
- Syntax:
data.crc32(bytes) - Parameters:
bytes:string
- Returns:
string - Purpose: Computes the CRC-32 digest of the input.
The result is a 4-byte binary digest, not hexadecimal text.
- Syntax:
data.md5(bytes)data.md5(bytes, hmacKey)
- Parameters:
bytes:stringhmacKey:string: optional HMAC key, Tier 2+ only.
- Returns:
string - Purpose: Computes either an MD5 digest or an HMAC-MD5 digest.
Notes:
- Plain MD5 exists on Tier 1.
- The HMAC form requires Tier 2 or higher.
- The result is binary data.
- Syntax:
data.sha256(bytes)data.sha256(bytes, hmacKey)
- Parameters:
bytes:stringhmacKey:string: optional HMAC key, Tier 2+ only.
- Returns:
string - Purpose: Computes either a SHA-256 digest or an HMAC-SHA256 digest.
The result is binary data.
- Syntax:
data.decodeNBT(bytes) - Parameters:
bytes:string: gzipped binary NBT payload.
- Returns:
table - Purpose: Decodes compressed binary NBT data into a Lua table representation.
This is useful for inspecting serialized Minecraft data blobs.
- Syntax:
data.encrypt(bytes, key, iv) - Parameters:
bytes:string: plaintext data.key:string: exactly 16 bytes.iv:string: exactly 16 bytes.
- Returns:
string - Purpose: Encrypts data with
AES/CBC/PKCS5Padding.
Failure cases:
- wrong key length:
expected a 128-bit AES key - wrong IV length:
expected a 128-bit AES IV
The result is binary ciphertext.
- Syntax:
data.decrypt(bytes, key, iv) - Parameters:
bytes:string: ciphertext.key:string: exactly 16 bytes.iv:string: exactly 16 bytes.
- Returns:
string - Purpose: Decrypts
AES/CBC/PKCS5Paddingciphertext.
The returned plaintext is raw bytes.
- Syntax:
data.random(length) - Parameters:
length:number: number of random bytes to generate.
- Returns:
string - Purpose: Returns cryptographically secure random bytes.
Valid range:
1to1024
Invalid lengths throw:
length must be in range [1..1024]
- Syntax:
data.generateKeyPair([bitLen]) - Parameters:
bitLen:number: optional curve size,256or384. Defaults to384.
- Returns:
userdata, userdata - Purpose: Generates an EC public/private key pair.
Return order:
- first value: public key userdata
- second value: private key userdata
Invalid sizes throw:
invalid key length, must be 256 or 384
- Syntax:
data.deserializeKey(bytes, typeName) - Parameters:
bytes:string: serialized key bytes.typeName:string:ec-publicorec-private.
- Returns:
userdata - Purpose: Restores an EC key userdata object from serialized bytes.
Invalid type names throw:
invalid key type, must be ec-public or ec-private
- Syntax:
data.ecdh(privateKey, publicKey) - Parameters:
privateKey:userdata: EC private key userdata.publicKey:userdata: EC public key userdata.
- Returns:
string - Purpose: Derives a shared secret using ECDH.
The result is raw binary secret data.
Argument mismatches throw errors such as:
private key expected at 1public key expected at 2
- Syntax:
data.ecdsa(bytes, privateKey)data.ecdsa(bytes, publicKey, signature)
- Parameters:
bytes:string: message bytes.privateKey:userdata: for signing mode.publicKey:userdata: for verify mode.signature:string: binary signature to verify.
- Returns:
- Signing mode:
string - Verify mode:
boolean
- Signing mode:
- Purpose: Signs or verifies data with
SHA256withECDSA.
Behavior:
- With no signature argument, the function signs and returns a binary signature.
- With a signature argument, the function verifies and returns
trueorfalse.
The objects returned by generateKeyPair() and deserializeKey() expose their own methods.
- Syntax:
key.isPublic() - Returns:
boolean - Purpose: Returns whether the key userdata wraps a public key.
- Syntax:
key.keyType() - Returns:
string - Purpose: Returns
ec-publicorec-private.
- Syntax:
key.serialize() - Returns:
string - Purpose: Returns the encoded binary form of the key.
Use data.encode64() if you need to store or print it safely.
local component = require("component")
local data = component.data
local digest = data.sha256("hello world")
print("sha256(base64):", data.encode64(digest))
local publicKey, privateKey = data.generateKeyPair(256)
local signature = data.ecdsa("message", privateKey)
print("signature ok:", data.ecdsa("message", publicKey, signature))
local secret = data.random(16)
local iv = data.random(16)
local cipher = data.encrypt("secret text", secret, iv)
print("cipher(base64):", data.encode64(cipher))
print("plain:", data.decrypt(cipher, secret, iv))databaseinternet