- Documentation
- Shared functions
- generateKeyPair
Function
generateKeyPair
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, optionalfunction(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
encodeStringEncrypts, encodes or compresses text. Works on the server and on the client. Algorithms:tea(raw TEA bytes, no base64),aes128(the key must be exactly 16 characters; it also returns a randomivneeded to decrypt),rsa(a public key fromgenerateKeyPair),base64(varianturl),base32(the Crypto++ alphabet, varianthex= RFC 4648 base32hex),zlib(formatgzip,zliborraw, level 0-9, strategy). Withbase64,base32andzlibthe options table can be left out. With a callback the result goes to it in the next frame and the function returnstrue.decodeStringDecrypts, decodes or unpacks data fromencodeString, also data made on another server. Withaes128you pass the key and theiv, withrsathe private key; withzlibthe format can be left out: gzip, zlib and raw are recognised by their header. Characters outside thebase64andbase32alphabets are skipped. Works on the server and on the client.