github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/app/lib/crypto1/hmac/hmac.js (about) 1 /*! 2 * Crypto-JS v1.1.0 3 * http://code.google.com/p/crypto-js/ 4 * Copyright (c) 2009, Jeff Mott. All rights reserved. 5 * http://code.google.com/p/crypto-js/wiki/License 6 */ 7 (function(){ 8 9 // Shortcut 10 var util = Crypto.util; 11 12 Crypto.HMAC = function (hasher, message, key, options) { 13 14 // Allow arbitrary length keys 15 key = key.length > hasher._blocksize * 4 ? 16 hasher(key, { asBytes: true }) : 17 util.stringToBytes(key); 18 19 // XOR keys with pad constants 20 var okey = key, 21 ikey = key.slice(0); 22 for (var i = 0; i < hasher._blocksize * 4; i++) { 23 okey[i] ^= 0x5C; 24 ikey[i] ^= 0x36; 25 } 26 27 var hmacbytes = hasher(util.bytesToString(okey) + 28 hasher(util.bytesToString(ikey) + message, { asString: true }), 29 { asBytes: true }); 30 return options && options.asBytes ? hmacbytes : 31 options && options.asString ? util.bytesToString(hmacbytes) : 32 util.bytesToHex(hmacbytes); 33 34 }; 35 36 })();