KeyObject
Node.js uses a KeyObject class to represent a symmetric or asymmetric key, and each kind of key exposes different functions. The {@link createSecretKey}, {@link createPublicKey} and {@link createPrivateKey} methods are used to create KeyObjectinstances. KeyObject objects are not to be created directly using the newkeyword.
Most applications should consider using the new KeyObject API instead of passing keys as strings or Buffers due to improved security features.
KeyObject instances can be passed to other threads via postMessage(). The receiver obtains a cloned KeyObject, and the KeyObject does not need to be listed in the transferList argument.
Since
v11.6.0
Properties
This property exists only on asymmetric keys. Depending on the type of the key, this object contains information about the key. None of the information obtained through this property can be used to uniquely identify a key or to compromise the security of the key.
For asymmetric keys, this property represents the type of the key. See the supported asymmetric key types.
For secret keys, this property represents the size of the key in bytes. This property is undefined for asymmetric keys.
Depending on the type of this KeyObject, this property is either'secret' for secret (symmetric) keys, 'public' for public (asymmetric) keys or 'private' for private (asymmetric) keys.
Functions
Returns true or false depending on whether the keys have exactly the same type, value, and parameters. This method is not constant time.
Converts a KeyObject instance to a CryptoKey.