阿西河

所有教程

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

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      Node.js crypto.getDiffieHellman

      Node.js crypto.getDiffieHellman(groupName)

      新增于: v0.7.5

      • groupName < string>
      • Returns:

      Creates a predefined DiffieHellman key exchange object. The supported groups are: ‘modp1’, ‘modp2’, ‘modp5’ (defined in RFC 2412, but see Caveats) and ‘modp14’, ‘modp15’, ‘modp16’, ‘modp17’, ‘modp18’ (defined in RFC 3526). The returned object mimics the interface of objects created by crypto.createDiffieHellman(), but will not allow changing the keys (with diffieHellman.setPublicKey(), for example). The advantage of using this method is that the parties do not have to generate nor exchange a group modulus beforehand, saving both processor and communication time.

      Example (obtaining a shared secret):

      const crypto = require('crypto');
      const alice = crypto.getDiffieHellman('modp14');
      const bob = crypto.getDiffieHellman('modp14');
      
      alice.generateKeys();
      bob.generateKeys();
      
      const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
      const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
      
      /* aliceSecret and bobSecret should be the same */
      console.log(aliceSecret === bobSecret);
      

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


      目录
      本文目录
      目录