Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PrivateKey

PKCS#8 Private Key

Hierarchy

Index

Constructors

constructor

Properties

Protected _finalKey

_finalKey: Buffer

Protected _finalPEM

_finalPEM: string

Protected _keyRaw

_keyRaw: Buffer

Protected _pkcs8

_pkcs8: ASN1

Protected _publicKeyRaw

_publicKeyRaw: Buffer | null

algo

algo: string

oid

oid: string

version

version: number

Static Private _signers

_signers: object = Object.create(null)

Type declaration

Accessors

keyRaw

  • get keyRaw(): Buffer
  • underlying key buffer

    Returns Buffer

publicKeyRaw

  • get publicKeyRaw(): Buffer | null
  • Returns publicKey buffer, it is used for Ed25519/Ed448.

    Returns Buffer | null

Methods

Protected __computed

  • __computed(_depth: any, options: any): string
  • Parameters

    • _depth: any
    • options: any

    Returns string

sign

  • sign(data: Buffer, hashAlgorithm: string): Buffer
  • Returns signature for the given data and hash algorithm.

    Parameters

    • data: Buffer
    • hashAlgorithm: string

    Returns Buffer

toASN1

  • toASN1(): ASN1
  • Returns an ASN.1 object of this PrivateKey

    Returns ASN1

toDER

  • toDER(): Buffer
  • Returns an DER formatted buffer of this PrivateKey

    Returns Buffer

toJSON

  • toJSON(): any
  • Return a friendly JSON object for debuging.

    Returns any

toPEM

  • toPEM(): string
  • Returns an PEM formatted string of this PrivateKey

    Returns string

Static addSigner

  • addSigner(oid: string, fn: Signer): void
  • Registers an external Signer with object identifier. Built-in verifiers: Ed25519, RSA, others see https://nodejs.org/api/crypto.html#crypto_class_sign

    PrivateKey.addSigner(getOID('Ed25519'), function (this: PrivateKey, data: Buffer): Buffer {
      const key = this.keyRaw
      if (key.length !== 64) {
        throw new Error('Invalid signing key.')
      }
      return Buffer.from(ed25519.detached(data, key))
    })

    Parameters

    • oid: string

      algorithm object identifier

    • fn: Signer

      Verifier function

    Returns void

Static fromPEM

  • Parse an PrivateKey for X.509 certificate from PKCS#8 PEM formatted buffer or PKCS#1 RSA PEM formatted buffer.

    Parameters

    • pem: Buffer

      PEM formatted buffer

    Returns PrivateKey

Generated using TypeDoc