Input to Has Algorithm
To obtain a hash of a partial CRN set of data, the input stream to the hash algorithm can be thought of as a file. A file is not at all required, but it is useful for descriptive purposes below. The input MUST match the following format, byte for byte, or the hashes calculated by the client and server will not match.
The format of the file (or an input stream) is as follows:
<CRN>,<ROR>,<SHA1>\n
<CRN>,<ROR>,<SHA1>\n
...and so on, one line per active CRN...
<CRN>,<ROR>,<SHA1>\n
The following points are required by the hash calculation:
The number of lines depends on the number of CRNs in the query. A partial CRN of "800" results in one line for every CRN with a prefix of 800.
The input MUST be ordered by the CRN, ascending.
The CRN, ROR, and SHA1 are printable strings like "8005551212", "AM123", and "acb2237d0679ca88db6464eac60da9634d51396a".
There is a comma (no spaces) between the fields on each line. Each [CRN,ROR,SHA1] combination ends with a single carriage return character, \n. (Not \r\n). Like all other lines, the last line has a CRN, ROR, and SHA1, followed by a single terminating \n character.
The SHA-1 hash is sent in lower case hexadecimal.
If a request for a partial CRN results in no data (no matching CRNs), then the file (or input stream) is empty. The hash of an empty stream is:
da39a3ee5e6b4b0d3255bfef95601890afd80709
This can be demonstrated on a Linux host as follows:
$ echo -n "" | sha1sum
da39a3ee5e6b4b0d3255bfef95601890afd80709
The following statement is an example MySQL query run on a Linux host. This query can be used as a guide for creating a file formatted with the above rules. The query makes assumptions about the DB schema, so modify it as needed.
$ echo "SELECT CONCAT_WS(',', crn, ror, sha1) \
FROM myCrnTable \
WHERE ( crn LIKE '800%') \
ORDER BY crn" \
| mysql MyDB -u MyUser -p MyPwd \
--disable-column-names \
> myfile.txt
The following file is an example (SampleAuditFile1.txt) for the partial CRN "866449874". Since the partial CRN has only 9 digits the hash is for the range "8664498740" .. "8664498749". For this example, it is assumed that all CRNs have the same ROR and CPR SHA1. It is also assumed that there are only 4 active CRNs in this range: the CRNs ending in 1, 3, 7, and 9:
8664498741,AM467,acb2237d0679ca88db6464eac60da96345513964
8664498743,AM467,acb2237d0679ca88db6464eac60da96345513964
8664498747,AM467,acb2237d0679ca88db6464eac60da96345513964
8664498749,AM467,acb2237d0679ca88db6464eac60da96345513964
This file becomes input to the SHA-1 hash algorithm. The reader is encouraged to create the above file and apply a SHA-1 hash generator to it to confirm the hash value below. There are several online hash generators available on the web (search for “sha-1 generator”). The correct hash for the above file is:
074d2a57e223dcf033cd44d14242036912c3ea8a
If you are working in a Linux environment, the following command may be available:
$ sha1sum SampleAuditFile1.txt
074d2a57e223dcf033cd44d14242036912c3ea8a SampleAuditFile1.txt