ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. generateKeyPair

Function

generateKeyPair

Server and clientMiscellaneousIdentical to MTA:SA

Creates an RSA key pair: private (PKCS#8) and public (X.509), both as binary DER data. To store them in a file or a database turn them into text, e.g. with base64Encode. encodeString/decodeString also accept PEM keys. Size 512-8192 bits (default 2048; on the client a multiple of 64). With a callback the keys go to it.

Syntax

string, string generateKeyPair(string algorithm, table options [, function callback])

Arguments

algorithmstring
"rsa".
optionstable
{ size = 2048 }.
callbackfunction, optional
function(privateKey, publicKey).

Returns

The private and the public key or false.

Example

local private, public = generateKeyPair("rsa", { size = 2048 })
local file = fileCreate("klucz_publiczny.txt")
fileWrite(file, base64Encode(public))
fileClose(file)

See also