![]()
First download the appropriate files from the links on the main page. Save them in the same directory as your html file and insert the appropriate one of these tags:
The scripts don't interfere with each other - you can use them all in the same document. Alternatively, you can copy the code and paste it straight into your html file, inside <script>...</script>. I personally prefer keeping the code separate, but inlining it is slightly faster.
Usually you'll want to get the result in hexadecimal, so it can be submitted as part of a form without worrying about URL encoding.
You can also get the result in base-64 encoding:
You can also get the result as a binary string; this is discussed below.
In many uses of hashes you end up wanting to combine a key with some data. It isn't so bad to do this by simple concatonation, but HMAC is a carefully designed method, known to be very secure. The usage is:
The HMAC result is also available base-64 encoded or as a binary string, using
b64_hmac_* or str_hmac_*.
There are a few configurable variables; you may have to tweak these to be compatible with the hash function on the server.
To set a variable, use a syntax like this:
In general, it's ok to change the values of these variables between calls to the library; so you can do ASCII and UniCode hashes on the same page, for example. However, you can't change chrsz and then re-use data returned by a str_* function.
This representation is useful when you want to feed the result of a hash operation back into another operation. The ability to do this lets you create a variety of cryptographic protocols. For example, to do a double hash:
The string is encoded so each character of a string represents either one or two bytes, in ASCII and UniCode respectively. This would be troublesome to send over HTTP as form data, but JavaScript strings are completely binary safe.
© 1998 - 2003 Paul Johnston, distributed under the BSD License Updated: 27 Jul 2003 |