EllipticCurveCryptography
Elliptic Curve Cryptography
Guessing the source is here: https://www.computercraft.info/forums2/index.php?/topic/29803-elliptic-curve-cryptography/
Functions
isByteTable
EllipticCurveCryptography.
isByteTable
(
key:
any
) →
boolean
Returns true if it's an ByteTable
createByteTable
EllipticCurveCryptography.
createByteTable
(
value:
any
) →
(
)
Adds the byte table to the value
encrypt
EllipticCurveCryptography.
encrypt
(
data:
string
|
ByteTable
,
key:
ByteTable
) →
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
(
data:
string
|
ByteTable
,
key:
ByteTable
) →
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
(
seed:
number
) →
(
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
(
privateKey:
ByteTable
,
publicKey:
ByteTable
) →
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
(
privateKey:
ByteTable
,
message:
string
|
EncodedMessage
) →
ByteTable
Signs the message with a private key
local signature = ECC.sign(clientPrivate, data)
verify
EllipticCurveCryptography.
verify
(
publicKey:
ByteTable
,
message:
ByteTable
|
string
,
signature:
ByteTable
) →
(
)
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)