I need to generate a hash on each uploaded file. The hash must be identical to hash git generated for a given file (which is, in a layman term, a variant of sha1).
I looked into /nodejs-v0.10.22-src/core-modules-sources/lib/crypto.js
. The library refers to native binding. For portability, I do not want to depends on native code.
Is there a way to add a custom crypto algorithm into nodejs crypto module, in JavaScript, such that I can do these:
var hash = crypto.createHash('githash');
hash.update('...');
The quick answer is no, you can't extend the hashes available in the
crypto
module. The given hash is checked at https://github.com/joyent/node/blob/v0.10.22/src/node_crypto.cc#L2856 and basically depends on the hashes supported by OpenSSL.You may be able to potentially monkey-patch
createHash
to redirect to your own code, but wouldn't be advisable.Instead, I'd recommend reworking your middleware usage to hash the data after the bodyParser is complete, or skip the standard bodyParser and implement your own for your specific use-case.