diffieHellman.generateKeys([encoding])


生成私有和公有的 Diffie-Hellman 密钥值,除非这些密钥值已经生成或计算过,并返回指定 encoding 的公钥。此密钥应传输给另一方。如果提供了 encoding,则返回一个字符串;否则返回一个 Buffer

🌐 Generates private and public Diffie-Hellman key values unless they have been generated or computed already, and returns the public key in the specified encoding. This key should be transferred to the other party. If encoding is provided a string is returned; otherwise a Buffer is returned.

此函数是 DH_generate_key() 的一个薄封装器。特别地,一旦生成或设置了私钥,调用此函数只会从现有私钥重新计算公钥。由于公钥由私钥决定,除非通过 diffieHellman.setPrivateKey() 更改了私钥,否则结果将相同。

🌐 This function is a thin wrapper around DH_generate_key(). In particular, once a private key has been generated or set, calling this function only recomputes the public key from the existing private key. Since the public key is determined by the private key, the result will be the same unless the private key has been changed via diffieHellman.setPrivateKey().