阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.scryptSync

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

      版本变更
      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.
      • Returns: < Buffer>

      Provides a synchronous 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.

      An exception is thrown when key derivation fails, otherwise the derived key is returned 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.
      const key1 = crypto.scryptSync('secret', 'salt', 64);
      console.log(key1.toString('hex'));  // '3745e48...08d59ae'
      // Using a custom N parameter. Must be a power of two.
      const key2 = crypto.scryptSync('secret', 'salt', 64, { N: 1024 });
      console.log(key2.toString('hex'));  // '3745e48...aa39b34'
      

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


      目录
      本文目录
      目录