diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index 702a9c32f7e..78284b35ac1 100644 --- a/doc/api/crypto.markdown +++ b/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`.