Using the C++ SHA-1 code
Hashing:
The class provided is a powerful tool for handling SHA-1 hashing. It provides many
ways of getting a digest and presenting the results. We will explain the most important
methods here.
- First, you must create an object of type CSHA1.
- If you already have a CSHA1 object and are re-using it, call Reset() before each use.
- To hash something that you have in memory, call
Update(unsigned char* data, unsigned int len).
- data is a pointer to what you want hashed
- len is the size of the data
- Call Final() before getting the output.
- Get the output using either
ReportHash(char *szReport, unsigned char uReportType)
or
GetHash(unsigned char *uDest)
- If you use ReportHash, you should pass it a buffer to a char [] that you have already created.
ReportHash will convert the digest to a string and fill your buffer. uReportType can be either
CSHA1::REPORT_HEX or CSHA1::REPORT_DIGIT. CSHA1::REPORT_HEX will give you a string representing
the hex values of the digest (ex: "5F A9 FB 34..."). CSHA1::REPORT_DIGIT will give you a string
representing the decimal values of the digest (ex: 129 67 5 98...). Make sure that the buffer
you provide is capable of holding the maximum possible length of the output string (60 bytes for
REPORT_HEX and 80 bytes for REPORT_DIGIT).
- If you use GetHash, you should pass it a 20 byte buffer (usigned char [20]) as uDest.
it will fill the 20 bytes (160 bits) of your buffer with the hash digest.
- You may reuse the same CSHA1 object to get another hash, but you must first call Reset()