Pusher REST JS SDK
by Ryan Duffy
JavaScript
/*
* jssha256 version 0.1 - Copyright 2006 B. Poettering
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
/*
* http://point-at-infinity.org/jssha256/
*
* This is a JavaScript implementation of the SHA256 secure hash function
* and the HMAC-SHA256 message authentication code (MAC).
*
* The routines' well-functioning has been verified with the test vectors
* given in FIPS-180-2, Appendix B and IETF RFC 4231. The HMAC algorithm
* conforms to IETF RFC 2104.
*
* The following code example computes the hash value of the string "abc".
*
* SHA256_init();
* SHA256_write("abc");
* digest = SHA256_finalize();
* digest_hex = array_to_hex_string(digest);
*
* Get the same result by calling the shortcut function SHA256_hash:
*
* digest_hex = SHA256_hash("abc");
*
* In the following example the calculation of the HMAC of the string "abc"
* using the key "secret key" is shown:
*
* HMAC_SHA256_init("secret key");
* HMAC_SHA256_write("abc");
* mac = HMAC_SHA256_finalize();
* mac_hex = array_to_hex_string(mac);
*
* Again, the same can be done more conveniently:
*
* mac_hex = HMAC_SHA256_MAC("secret key", "abc");
*
* Note that the internal state of the hash function is held in global
* variables. Therefore one hash value calculation...