FileGetHash
Jump to navigation
Jump to search
Syntax
nil|string fileGetHash ( file theFile, string algorithm [, table options ] )
OOP Syntax Help! I don't understand this!
- Method: file:getHash(...)
Required Arguments
- theFile: A handle to the file you wish to get the hash from. Use fileOpen to obtain this handle.
- algorithm: A string which must be one of these: "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "hmac"
Optional arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.
- 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 entire file on success, and nil on failure.
Example
This example opens the code.lua file, computes the hash with every algorithm, and then displays them.
local handle = fileOpen("code.lua", true) local hashMD5 = fileGetHash(handle, "md5") local hashSHA1 = fileGetHash(handle, "sha1") local hashSHA224 = fileGetHash(handle, "sha224") local hashSHA256 = fileGetHash(handle, "sha256") local hashSHA384 = fileGetHash(handle, "sha384") local hashSHA512 = fileGetHash(handle, "sha512") local hashHMAC = fileGetHash(handle, "hmac", { algorithm = "sha256", key = "blue apple tree" }) fileClose(handle) iprint("MD5", hashMD5) iprint("SHA1", hashSHA1) iprint("SHA224", hashSHA224) iprint("SHA256", hashSHA256) iprint("SHA384", hashSHA384) iprint("SHA512", hashSHA512) iprint("HMAC-SHA256", hashHMAC )
See Also
- fileClose
- fileCopy
- fileCreate
- fileDelete
- fileExists
- fileFlush
- fileGetPath
- fileGetPos
- fileGetSize
- fileIsEOF
- fileOpen
- fileRead
- fileRename
- fileSetPos
- fileWrite