Browse Source

Add example to sha1 docs

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
dcc2dd5e1f
  1. 18
      doc/api/crypto.markdown

18
doc/api/crypto.markdown

@ -29,6 +29,24 @@ which can be used to generate hash digests.
of OpenSSL on the platform. Examples are `'sha1'`, `'md5'`, `'sha256'`, `'sha512'`, etc.
On recent releases, `openssl list-message-digest-algorithms` will display the available digest algorithms.
Example: this program that takes the sha1 sum of a file
var filename = process.argv[2];
var crypto = require('crypto');
var fs = require('fs');
var shasum = crypto.createHash('sha1');
var s = fs.ReadStream(filename);
s.on('data', function(d) {
shasum.update(d);
});
s.on('end', function() {
var d = shasum.digest('hex');
console.log(d + ' ' + filename);
});
### hash.update(data)
Updates the hash content with the given `data`.

Loading…
Cancel
Save