Skip to main content

EllipticCurveCryptography

Functions

isByteTable

EllipticCurveCryptography.isByteTable(keyany) → boolean

Returns true if it's an ByteTable

createByteTable

EllipticCurveCryptography.createByteTable(valueany) → ()

Adds the byte table to the value

encrypt

EllipticCurveCryptography.encrypt(
datastring | ByteTable,
keyByteTable
) → ByteTable

Encrypts the data using the shared secret

local data = "Hello"

local sharedSecret = ECC.exchange(serverPrivate, clientPublic)
local encryptedData = ECC.encrypt(data, sharedSecret)

-- Ensures the output is consistent
local signature = ECC.sign(clientPrivate, data)

-- These 2 items are the output
print(encryptedData, signature)

decrypt

EllipticCurveCryptography.decrypt(
datastring | ByteTable,
keyByteTable
) → ByteTable

Decrypts the data using the shared secret

local sharedSecret = ECC.exchange(serverPrivate, clientPublic)
local data = ECC.decrypt(encryptedData, sharedSecret)

print(tostring(data))

keypair

EllipticCurveCryptography.keypair(seednumber) → (
ByteTable,--

privateKey

ByteTable--

publicKey

)

Exchanges a private and public key to get a shared secret from two public keys.

local ECC = require("EllipticCurveCryptography")

local serverPrivate, serverPublic = ECC.keypair(ECC.random.random())
local sharedSecret = ECC.exchange(serverPrivate, clientPublic)

exchange

EllipticCurveCryptography.exchange(
privateKeyByteTable,
publicKeyByteTable
) → ByteTable

Exchanges a private and public key to get a shared secret from two public keys.

This allows for each the client and the server to encrypt and send data to each other securely.

local ECC = require("EllipticCurveCryptography")

local serverPrivate, serverPublic = ECC.keypair(ECC.random.random())
local sharedSecret = ECC.exchange(serverPrivate, clientPublic),

sign

EllipticCurveCryptography.sign(
privateKeyByteTable,
messagestring | EncodedMessage
) → ByteTable

Signs the message with a private key

local signature = ECC.sign(clientPrivate, data)

verify

EllipticCurveCryptography.verify(
publicKeyByteTable,
messageByteTable | string,
signatureByteTable
) → ()

Verifies that the message was signed with the public key and signature and ensures that the value is safe

local data = ECC.decrypt(encryptedData, sharedSecret)
local verified = ECC.verify(clientPublic, data, signature)
Show raw api
{
    "functions": [
        {
            "name": "isByteTable",
            "desc": "Returns true if it's an ByteTable",
            "params": [
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 54,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "createByteTable",
            "desc": "Adds the byte table to the value",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 63,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "encrypt",
            "desc": "Encrypts the data using the shared secret\n\n```lua\nlocal data = \"Hello\"\n\nlocal sharedSecret = ECC.exchange(serverPrivate, clientPublic)\nlocal encryptedData = ECC.encrypt(data, sharedSecret)\n\n-- Ensures the output is consistent\nlocal signature = ECC.sign(clientPrivate, data)\n\n-- These 2 items are the output\nprint(encryptedData, signature)\n```",
            "params": [
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "string | ByteTable"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 100,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "decrypt",
            "desc": "Decrypts the data using the shared secret\n\n```lua\nlocal sharedSecret = ECC.exchange(serverPrivate, clientPublic)\nlocal data = ECC.decrypt(encryptedData, sharedSecret)\n\nprint(tostring(data))\n```",
            "params": [
                {
                    "name": "data",
                    "desc": "",
                    "lua_type": "string | ByteTable"
                },
                {
                    "name": "key",
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 137,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "keypair",
            "desc": "Exchanges a private and public key to get a shared secret from two\npublic keys.\n\n```lua\nlocal ECC = require(\"EllipticCurveCryptography\")\n\nlocal serverPrivate, serverPublic = ECC.keypair(ECC.random.random())\nlocal sharedSecret = ECC.exchange(serverPrivate, clientPublic)\n```",
            "params": [
                {
                    "name": "seed",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "privateKey",
                    "lua_type": "ByteTable"
                },
                {
                    "desc": "publicKey",
                    "lua_type": "ByteTable"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 169,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "exchange",
            "desc": "Exchanges a private and public key to get a shared secret from two\npublic keys.\n\nThis allows for each the client and the server to encrypt and\nsend data to each other securely.\n\n```lua\nlocal ECC = require(\"EllipticCurveCryptography\")\n\nlocal serverPrivate, serverPublic = ECC.keypair(ECC.random.random())\nlocal sharedSecret = ECC.exchange(serverPrivate, clientPublic),\n```",
            "params": [
                {
                    "name": "privateKey",
                    "desc": "",
                    "lua_type": "ByteTable"
                },
                {
                    "name": "publicKey",
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 205,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "sign",
            "desc": "Signs the message with a private key\n\n```lua\nlocal signature = ECC.sign(clientPrivate, data)\n```",
            "params": [
                {
                    "name": "privateKey",
                    "desc": "",
                    "lua_type": "ByteTable"
                },
                {
                    "name": "message",
                    "desc": "",
                    "lua_type": "string | EncodedMessage"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 229,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        },
        {
            "name": "verify",
            "desc": "Verifies that the message was signed with the public key and signature and ensures\nthat the value is safe\n\n```lua\nlocal data = ECC.decrypt(encryptedData, sharedSecret)\nlocal verified = ECC.verify(clientPublic, data, signature)\n```",
            "params": [
                {
                    "name": "publicKey",
                    "desc": "",
                    "lua_type": "ByteTable"
                },
                {
                    "name": "message",
                    "desc": "",
                    "lua_type": "ByteTable | string"
                },
                {
                    "name": "signature",
                    "desc": "",
                    "lua_type": "ByteTable"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 267,
                "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "EllipticCurveCryptography",
    "desc": "Elliptic Curve Cryptography\n\nGuessing the source is here: https://www.computercraft.info/forums2/index.php?/topic/29803-elliptic-curve-cryptography/",
    "source": {
        "line": 9,
        "path": "src/ellipticcurvecryptography/src/Shared/EllipticCurveCryptography/init.lua"
    }
}