阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.createHash

      Node.js crypto.createHash(algorithm[, options])

      新增于: v0.1.92

      • algorithm < string>
      • options < Object> stream.transform options
      • Returns:

      Creates and returns a Hash object that can be used to generate hash digests using the given algorithm. Optional options argument controls stream behavior.

      The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform. Examples are ‘sha256’, ‘sha512’, etc. On recent releases of OpenSSL, openssl list -digest-algorithms (openssl list-message-digest-algorithms for older versions of OpenSSL) will display the available digest algorithms.

      Example: generating the sha256 sum of a file

      const filename = process.argv[2];
      const crypto = require('crypto');
      const fs = require('fs');
      
      const hash = crypto.createHash('sha256');
      
      const input = fs.createReadStream(filename);
      input.on('readable', () => {
        const data = input.read();
        if (data)
          hash.update(data);
        else {
          console.log(`${hash.digest('hex')} ${filename}`);
        }
      });
      

      更多内容请参考:Node.js crypto 加密,或者通过 点击对应菜单 进行查看;


      目录
      本文目录
      目录