Hash: Difference between revisions
Jump to navigation
Jump to search
(HMAC documentaction) |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 4: | Line 4: | ||
This function returns a hash of the specified string in the specified algorithm. | This function returns a hash of the specified string in the specified algorithm. | ||
}} | }} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
string hash ( string algorithm, string dataToHash ) | string hash ( string algorithm, string dataToHash, [ table options ] ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''algorithm''': A string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512" | *'''algorithm''': A string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "hmac" | ||
*'''dataToHash''': A string of the data to hash. | *'''dataToHash''': A string of the data to hash. | ||
*'''options''': A table with options and other necessary data for the algorithm, as detailed below. | |||
===Options for each algorithm=== | |||
{{Added feature/item|1.5.9|1.5.8|21329| | |||
* ''hmac'' ([https://en.wikipedia.org/wiki/HMAC HMAC]) | |||
** '''key''': a key to encode the input with. | |||
** '''algorithm''': a string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512". | |||
|21329}} | |||
===Returns=== | ===Returns=== | ||
Line 20: | Line 27: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local myString = "myDatatoHash" | local myString = "myDatatoHash" | ||
print(hash("md5", myString)) -- This will hash myString with the md5 Algorithm (it's equal to md5()) | print(hash("md5", myString)) -- This will hash myString with the md5 Algorithm (it's equal to md5()) -> output: 0EF1E2203BD78182911B77EB6B9CC3DE | ||
-- A another Example | -- A another Example | ||
local myNewString = "myNewDatatoHash" | local myNewString = "myNewDatatoHash" | ||
print(hash("sha512", myNewString)) -- This will hash myNewString with the sha512 Algorithm | print(hash("sha512", myNewString)) -- This will hash myNewString with the sha512 Algorithm -> output: 64A5678DC83EDCD8991E8CF0D69764663C0F933870BB89465F77B6C23D2A2B2400305A36D77404EE647D0D7B9D56CF7937B235BBD3885D08DCC62C81FB6D8429 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 09:15, 25 September 2022
This function returns a hash of the specified string in the specified algorithm.
Syntax
string hash ( string algorithm, string dataToHash, [ table options ] )
Required Arguments
- algorithm: A string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "hmac"
- dataToHash: A string of the data to hash.
- options: A table with options and other necessary data for the algorithm, as detailed below.
Options for each algorithm
- hmac (HMAC)
- key: a key to encode the input with.
- algorithm: a string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512".
Returns
Returns the hash of the data, false if an invalid argument was used.
Example
local myString = "myDatatoHash" print(hash("md5", myString)) -- This will hash myString with the md5 Algorithm (it's equal to md5()) -> output: 0EF1E2203BD78182911B77EB6B9CC3DE -- A another Example local myNewString = "myNewDatatoHash" print(hash("sha512", myNewString)) -- This will hash myNewString with the sha512 Algorithm -> output: 64A5678DC83EDCD8991E8CF0D69764663C0F933870BB89465F77B6C23D2A2B2400305A36D77404EE647D0D7B9D56CF7937B235BBD3885D08DCC62C81FB6D8429
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