GenerateKeyPair
Jump to navigation
Jump to search
This function creates a new public key and private key for encrypting data
Syntax
string, string generateKeyPair ( string algorithm, table options [, function callback ] )
Required Arguments
- algorithm: The algorithm to use:
- RSA: use the RSA public-key algorithm
- options: table with options for the hashing algorithm, as detailed below.
Optional Arguments
- callback: providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.
Options for each hashing algorithm
- RSA:
- size (int), default: 0 . Size of a key.
Returns
Returns 2 strings if successful: private key and public key. Otherwise returns false
Example
Adds an /generatekeypair command in which you can provide a key size to generate a key pair for encryption.
Click to collapse [-]
ServeraddCommandHandler("generatekeypair", function(player, _, algorithm, keysize) if algorithm then if keysize and tonumber(keysize) then local privateKey, publicKey = generateKeyPair( algorithm, { size = keysize } ) if not privateKey then outputChatBox("Failed to generate key pair. Make sure that all arguments are valid.", player, 255, 0, 0) else outputConsole("Private Key: " .. base64Encode(privateKey),player) outputConsole("Public Key: " .. base64Encode(publicKey),player) outputChatBox("The key pair was successfully generated. You can find the result in the console.", player, 0, 255, 0) end else outputChatBox("Please specify key size in the command.", player, 255, 0, 0) end else outputChatBox("Please specify algorithm in the command.", player, 255, 0, 0) end end )
See Also
- addDebugHook
- base64Decode
- base64Encode
- debugSleep
- decodeString
- encodeString
- fromJSON
- generateKeyPair
- getColorFromString
- getDevelopmentMode
- getDistanceBetweenPoints2D
- getDistanceBetweenPoints3D
- getEasingValue
- getNetworkStats
- getNetworkUsageData
- getPerformanceStats
- getRealTime
- getTickCount
- getTimerDetails
- getTimers
- getFPSLimit
- getUserdataType
- getVersion
- gettok
- isTransferBoxVisible
- setTransferBoxVisible
- hash
- inspect
- interpolateBetween
- iprint
- isOOPEnabled
- isTimer
- killTimer
- md5
- passwordHash
- passwordVerify
- pregFind
- pregMatch
- pregReplace
- removeDebugHook
- resetTimer
- setDevelopmentMode
- setFPSLimit
- setTimer
- ref
- deref
- sha256
- split
- teaDecode
- teaEncode
- toJSON
- tocolor
- getProcessMemoryStats
- utfChar
- utfCode
- utfLen
- utfSeek
- utfSub
- bitAnd
- bitNot
- bitOr
- bitXor
- bitTest
- bitLRotate
- bitRRotate
- bitLShift
- bitRShift
- bitArShift
- bitExtract
- bitReplace