KeyObject

external class KeyObject(source)

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

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

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.

Link copied to clipboard

For asymmetric keys, this property represents the size of the embedded key in bytes. This property is undefined for symmetric keys.

Link copied to clipboard

For asymmetric keys, this property represents the type of the key. Supported key types are:

Link copied to clipboard

For secret keys, this property represents the size of the key in bytes. This property is undefined for asymmetric keys.

Link copied to clipboard

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

Link copied to clipboard
fun equals(otherKeyObject: KeyObject): Boolean

Returns true or false depending on whether the keys have exactly the same type, value, and parameters. This method is not constant time.

Link copied to clipboard
fun export(options: JwkKeyExportOptions = definedExternally): JsonWebKey
fun export(options: KeyExportOptions<KeyFormat.der> = definedExternally): Buffer