ecdh.computeSecret(otherPublicKey[, inputEncoding][, outputEncoding])
otherPublicKey<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView>inputEncoding<string>otherPublicKey字符串的 编码。outputEncoding<string> 返回值的 编码。- 返回: <Buffer> | <string>
使用 otherPublicKey 作为另一方的公钥计算共享密钥,并返回计算得到的共享密钥。提供的密钥将使用指定的 inputEncoding 进行解读,返回的密钥将使用指定的 outputEncoding 进行编码。如果未提供 inputEncoding,则 otherPublicKey 预计为 Buffer、TypedArray 或 DataView。
【Computes the shared secret using otherPublicKey as the other
party's public key and returns the computed shared secret. The supplied
key is interpreted using specified inputEncoding, and the returned secret
is encoded using the specified outputEncoding.
If the inputEncoding is not
provided, otherPublicKey is expected to be a Buffer, TypedArray, or
DataView.】
如果提供了 outputEncoding,将返回一个字符串;否则,将返回一个 Buffer。
【If outputEncoding is given a string will be returned; otherwise a
Buffer is returned.】
ecdh.computeSecret 当 otherPublicKey 位于椭圆曲线之外时会抛出 ERR_CRYPTO_ECDH_INVALID_PUBLIC_KEY 错误。由于 otherPublicKey 通常是从不安全网络上的远程用户提供的,请确保相应地处理此异常。