This file provides 2 stock functions to calculate the SHA-1 hash for a given string or file.
SHA-1, the Secure Hashing Algorithm, is used by the Secure Hashing Standard as defined in FIPS PUB 180-1 published April 17, 1995.
Since it's very unlikely, that 2 messages will result in the same hash, SHA-1 can be used as a fingerprint for a message.
PHP Code:
/**
* @brief Produces a 160-bit message digest for a given data stream
*
* @param str Input string to calculate the hash from.
* @param output Output buffer. If bHex is true, output must be at least 40+1 of length, if not it has to be 20+1.
* @param bHex If true, return the hash as hexadecimal number, else return a raw binary format.
* @return True, if hash was calculated, false otherwise
*/
stock bool:SHA1String(const String:str[], String:output[], bool:bHex=true)
/**
* @brief Produces a 160-bit message digest for a given file
*
* @param hFile File handle returned by OpenFile(path, "r");
* @param output Output buffer. If bHex is true, output must be at least 40+1 of length, if not it has to be 20+1.
* @param bHex If true, return the hash as hexadecimal number, else return a raw binary format.
* @return True, if hash was calculated, false otherwise
*/
stock bool:SHA1File(Handle:hFile, String:output[], bool:bHex=true)
Changelog:
- 13.02.2013: Fixed SHA1File compile errors