类:KeyObject


【Class: KeyObject

Node.js 使用 KeyObject 类来表示对称或非对称密钥,每种类型的密钥都提供不同的函数。crypto.createSecretKey()crypto.createPublicKey()crypto.createPrivateKey() 方法用于创建 KeyObject 实例。KeyObject 对象不应使用 new 关键字直接创建。

【Node.js uses a KeyObject class to represent a symmetric or asymmetric key, and each kind of key exposes different functions. The crypto.createSecretKey(), crypto.createPublicKey() and crypto.createPrivateKey() methods are used to create KeyObject instances. KeyObject objects are not to be created directly using the new keyword.】

大多数应用应考虑使用新的 KeyObject API,而不是将密钥作为字符串或 Buffer 传递,因为它具有更高的安全性特性。

【Most applications should consider using the new KeyObject API instead of passing keys as strings or Buffers due to improved security features.】

KeyObject 实例可以通过 postMessage() 传递给其他线程。接收方会获得一个克隆的 KeyObject,并且 KeyObject 无需在 transferList 参数中列出。