Packages

class KeyObject extends Object with StObject with _KeyLike

Node.js uses a KeyObject class to represent a symmetric or asymmetric key, and each kind of key exposes different functions. The createSecretKey, createPublicKey and 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.

Annotations
@JSType() @JSImport("crypto", "KeyObject") @native()
Since

v11.6.0

Linear Supertypes
_KeyLike, StObject, Object, Any, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. KeyObject
  2. _KeyLike
  3. StObject
  4. Object
  5. Any
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new KeyObject()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. var asymmetricKeyDetails: UndefOr[AsymmetricKeyDetails]

    This property exists only on asymmetric keys.

    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 RSA-PSS keys, if the key material contains a RSASSA-PSS-params sequence, the hashAlgorithm, mgf1HashAlgorithm, and saltLength properties will be set.

    Other key details might be exposed via this API using additional attributes.

    Since

    v15.7.0

  6. var asymmetricKeySize: UndefOr[Double]

    For asymmetric keys, this property represents the size of the embedded key in bytes.

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

  7. var asymmetricKeyType: UndefOr[KeyType]

    For asymmetric keys, this property represents the type of the key.

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

    * 'rsa' (OID 1.2.840.113549.1.1.1) * 'rsa-pss' (OID 1.2.840.113549.1.1.10) * 'dsa' (OID 1.2.840.10040.4.1) * 'ec' (OID 1.2.840.10045.2.1) * 'x25519' (OID 1.3.101.110) * 'x448' (OID 1.3.101.111) * 'ed25519' (OID 1.3.101.112) * 'ed448' (OID 1.3.101.113) * 'dh' (OID 1.2.840.113549.1.3.1)

    This property is undefined for unrecognized KeyObject types and symmetric keys.

    Since

    v11.6.0

  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  9. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  10. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  11. def export(options: JwkKeyExportOptions): JsonWebKey
  12. def export(): Buffer
  13. def export_JsonWebKey(): JsonWebKey
    Annotations
    @JSName("export")
  14. def export_der(options: KeyExportOptions[der]): Buffer
    Annotations
    @JSName("export")
  15. def export_pem(options: KeyExportOptions[pem]): |[String, Buffer]

    For symmetric keys, the following encoding options can be used:

    For symmetric keys, the following encoding options can be used:

    For public keys, the following encoding options can be used:

    For private keys, the following encoding options can be used:

    The result type depends on the selected encoding format, when PEM the result is a string, when DER it will be a buffer containing the data encoded as DER, when [JWK](https://tools.ietf.org/html/rfc7517) it will be an object.

    When [JWK](https://tools.ietf.org/html/rfc7517) encoding format was selected, all other encoding options are ignored.

    PKCS#1, SEC1, and PKCS#8 type keys can be encrypted by using a combination of the cipher and format options. The PKCS#8 type can be used with anyformat to encrypt any key algorithm (RSA, EC, or DH) by specifying acipher. PKCS#1 and SEC1 can only be encrypted by specifying a cipherwhen the PEM format is used. For maximum compatibility, use PKCS#8 for encrypted private keys. Since PKCS#8 defines its own encryption mechanism, PEM-level encryption is not supported when encrypting a PKCS#8 key. See [RFC 5208](https://www.rfc-editor.org/rfc/rfc5208.txt) for PKCS#8 encryption and [RFC 1421](https://www.rfc-editor.org/rfc/rfc1421.txt) for PKCS#1 and SEC1 encryption.

    Annotations
    @JSName("export")
    Since

    v11.6.0

  16. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  17. def hasOwnProperty(v: String): Boolean
    Definition Classes
    Object
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. def isPrototypeOf(v: Object): Boolean
    Definition Classes
    Object
  21. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  23. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  24. def propertyIsEnumerable(v: String): Boolean
    Definition Classes
    Object
  25. var symmetricKeySize: UndefOr[Double]

    For secret keys, this property represents the size of the key in bytes.

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

    Since

    v11.6.0

  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def toLocaleString(): String
    Definition Classes
    Object
  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. var type: KeyObjectType

    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.

    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.

    Since

    v11.6.0

  30. def valueOf(): Any
    Definition Classes
    Object
  31. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  33. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from _KeyLike

Inherited from StObject

Inherited from Object

Inherited from Any

Inherited from AnyRef

Inherited from Any

Ungrouped