tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])


稳定性: 0 - 已弃用:改用 tls.TLSSocket

¥Stability: 0 - Deprecated: Use tls.TLSSocket instead.

  • context <Object> tls.createSecureContext() 返回的安全上下文对象

    ¥context <Object> A secure context object as returned by tls.createSecureContext()

  • isServer <boolean> true 指定此 TLS 连接应作为服务器打开。

    ¥isServer <boolean> true to specify that this TLS connection should be opened as a server.

  • requestCert <boolean> true 指定服务器是否应向连接客户端请求证书。仅在 isServertrue 时适用。

    ¥requestCert <boolean> true to specify whether a server should request a certificate from a connecting client. Only applies when isServer is true.

  • rejectUnauthorized <boolean> 如果不是 false,则服务器会自动拒绝证书无效的客户端。仅在 isServertrue 时适用。

    ¥rejectUnauthorized <boolean> If not false a server automatically reject clients with invalid certificates. Only applies when isServer is true.

  • options

使用两个流创建新的安全对对象,其中一个读取和写入加密数据,另一个读取和写入明文数据。通常,加密流通过管道传输到/从传入的加密数据流,明文用作初始加密流的替代。

¥Creates a new secure pair object with two streams, one of which reads and writes the encrypted data and the other of which reads and writes the cleartext data. Generally, the encrypted stream is piped to/from an incoming encrypted data stream and the cleartext one is used as a replacement for the initial encrypted stream.

tls.createSecurePair() 返回具有 cleartextencrypted 流属性的 tls.SecurePair 对象。

¥tls.createSecurePair() returns a tls.SecurePair object with cleartext and encrypted stream properties.

使用 cleartexttls.TLSSocket 具有相同的 API。

¥Using cleartext has the same API as tls.TLSSocket.

现在不推荐使用 tls.createSecurePair() 方法而支持 tls.TLSSocket()。例如代码:

¥The tls.createSecurePair() method is now deprecated in favor of tls.TLSSocket(). For example, the code:

pair = tls.createSecurePair(/* ... */);
pair.encrypted.pipe(socket);
socket.pipe(pair.encrypted); 

可以替换为:

¥can be replaced by:

secureSocket = tls.TLSSocket(socket, options); 

其中 secureSocketpair.cleartext 具有相同的 API。

¥where secureSocket has the same API as pair.cleartext.