UNPKG

cryptojs-atom

Version:

It's a fork adapted to be used with package of the text editor atom. Following googlecode project crypto-js, provide standard and secure cryptographic algorithms for NodeJS. Support MD5, SHA-1, SHA-256, RC4, Rabbit, AES, DES, PBKDF2, HMAC, OFB, CFB, CTR,

39 lines (28 loc) 1.03 kB
(function(){ var C = require('./Crypto').Crypto; // Shortcuts var util = C.util, charenc = C.charenc, UTF8 = charenc.UTF8, Binary = charenc.Binary; C.HMAC = function (hasher, message, key, options) { // Convert to byte arrays if (message.constructor == String) message = UTF8.stringToBytes(message); if (key.constructor == String) key = UTF8.stringToBytes(key); /* else, assume byte arrays already */ // Allow arbitrary length keys if (key.length > hasher._blocksize * 4) key = hasher(key, { asBytes: true }); // XOR keys with pad constants var okey = key.slice(0), ikey = key.slice(0); for (var i = 0; i < hasher._blocksize * 4; i++) { okey[i] ^= 0x5C; ikey[i] ^= 0x36; } var hmacbytes = hasher(okey.concat(hasher(ikey.concat(message), { asBytes: true })), { asBytes: true }); return options && options.asBytes ? hmacbytes : options && options.asString ? Binary.bytesToString(hmacbytes) : util.bytesToHex(hmacbytes); }; })();