tls.createSecurePair([context][, isServer][, requestCert][, rejectUnauthorized][, options])
tls.TLSSocket。context<Object> 由tls.createSecureContext()返回的安全上下文对象isServer<boolean>true用于指定此 TLS 连接应以服务器模式打开。requestCert<boolean>true用于指定服务器是否应从连接的客户端请求证书。仅在isServer为true时适用。rejectUnauthorized<boolean> 如果不是false,服务器会自动拒绝具有无效证书的客户端。仅当isServer为true时适用。optionsenableTrace:参见tls.createServer()secureContext:来自tls.createSecureContext()的 TLS 上下文对象isServer:如果为true,TLS 套接字将以服务器模式实例化。 默认值:false。server<net.Server> 一个net.Server实例requestCert: 参见tls.createServer()rejectUnauthorized: 参见tls.createServer()ALPNProtocols:见tls.createServer()SNICallback:参见tls.createServer()session<Buffer> 一个包含 TLS 会话的Buffer实例。requestOCSP<boolean> 如果为true,则表示将在客户端问候消息中添加 OCSP 状态请求扩展,并在建立安全通信之前在套接字上触发'OCSPResponse'事件。
创建一个新的安全对对象,该对象包含两个流,其中一个用于读取和写入加密数据,另一个用于读取和写入明文数据。通常,加密流用于从传入的加密数据流中传输数据,而明文流则作为最初加密流的替代使用。
【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() 返回一个带有 cleartext 和 encrypted 流属性的 tls.SecurePair 对象。
使用 cleartext 的 API 与 tls.TLSSocket 相同。
【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); 其中 secureSocket 与 pair.cleartext 拥有相同的 API。
【where secureSocket has the same API as pair.cleartext.】