Skip to content

Commit

Permalink
Add example to sha1 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Apr 3, 2011
1 parent 3002c01 commit dcc2dd5
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doc/api/crypto.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit dcc2dd5

Please sign in to comment.