阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.scrypt

      Node.js crypto.scrypt(password, salt, keylen[, options], callback) 版本历史

      版本变更
      v10.9.0The cost, blockSize and parallelization option names have been added.
      v10.5.0新增于: v10.5.0
      • password < string> | < Buffer> ||
      • salt < string> | < Buffer> ||
      • keylen < number>
      • options < Object>
        • cost < number> CPU/memory cost parameter. Must be a power of two greater
        • N < number> CPU/memory cost parameter. Must be a power of two greater than one. Default: 16384.
        • blockSize < number> Block size parameter. Default: 8.
        • parallelization < number> Parallelization parameter. Default: 1.
        • N < number> Alias for cost. Only one of both may be specified.
        • r < number> Alias for blockSize. Only one of both may be specified.
        • p < number> Alias for parallelization. Only one of both may be specified.
        • maxmem < number> Memory upper bound. It is an error when (approximately) 128 * N * r > maxmem. Default: 32 * 1024 * 1024.
      • callback < Function>
        • err < Error>
        • derivedKey < Buffer>

      Provides an asynchronous scrypt implementation. Scrypt is a password-based key derivation function that is designed to be expensive computationally and memory-wise in order to make brute-force attacks unrewarding.

      The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details.

      The callback function is called with two arguments: err and derivedKey. err is an exception object when key derivation fails, otherwise err is null. derivedKey is passed to the callback as a Buffer.

      An exception is thrown when any of the input arguments specify invalid values or types.

      const crypto = require('crypto');
      // Using the factory defaults.
      crypto.scrypt('secret', 'salt', 64, (err, derivedKey) => {
        if (err) throw err;
        console.log(derivedKey.toString('hex'));  // '3745e48...08d59ae'
      });
      // Using a custom N parameter. Must be a power of two.
      crypto.scrypt('secret', 'salt', 64, { N: 1024 }, (err, derivedKey) => {
        if (err) throw err;
        console.log(derivedKey.toString('hex'));  // '3745e48...aa39b34'
      });
      

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


      目录
      本文目录
      目录