• groupName {string}
    • Returns: {DiffieHellmanGroup}

    Creates a predefined DiffieHellmanGroup 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):

    1. const crypto = require('crypto');
    2. const alice = crypto.getDiffieHellman('modp14');
    3. const bob = crypto.getDiffieHellman('modp14');
    4. alice.generateKeys();
    5. bob.generateKeys();
    6. const aliceSecret = alice.computeSecret(bob.getPublicKey(), null, 'hex');
    7. const bobSecret = bob.computeSecret(alice.getPublicKey(), null, 'hex');
    8. /* aliceSecret and bobSecret should be the same */
    9. console.log(aliceSecret === bobSecret);