View Single Post
Author Message
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 11-23-2011 , 06:43   [INC] SHA-1 hashing stocks
Reply With Quote #1

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:hFileString:output[], bool:bHex=true
Changelog:
  • 13.02.2013: Fixed SHA1File compile errors
Attached Files
File Type: inc sha1.inc (8.4 KB, 915 views)
__________________

Last edited by Peace-Maker; 02-12-2013 at 20:58. Reason: Fixed SHA1File compile errors
Peace-Maker is offline