Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PublicKey

PKCS#8 Public Key

Hierarchy

Index

Constructors

constructor

Properties

Protected _finalKey

_finalKey: Buffer

Protected _finalPEM

_finalPEM: string

Protected _keyRaw

_keyRaw: Buffer

Protected _pkcs8

_pkcs8: ASN1

algo

algo: string

oid

oid: string

Static Private _verifiers

_verifiers: object = Object.create(null)

Type declaration

Accessors

keyRaw

  • get keyRaw(): Buffer
  • underlying key buffer

    Returns Buffer

Methods

Protected __computed

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

    • _depth: any
    • options: any

    Returns string

getFingerprint

  • getFingerprint(hashAlgorithm: string, type?: string): Buffer
  • Returns the digest of the PublicKey with given hash algorithm.

    certificate.publicKey.getFingerprint('sha1', 'PublicKey') // => Buffer

    Parameters

    • hashAlgorithm: string

      hash algorithm, such as 'sha256', 'sha1'

    • Default value type: string = "PublicKey"

      'PublicKey' or 'PublicKeyInfo'

    Returns Buffer

toASN1

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

    Returns ASN1

toDER

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

    Returns Buffer

toJSON

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

    Returns any

toPEM

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

    Returns string

verify

  • verify(data: Buffer, signature: Buffer, hashAlgorithm: string): boolean
  • Returns true if the provided data and the given signature matched.

    certificate.publicKey.verify(data, signature, 'sha256') // => true or false

    Parameters

    • data: Buffer

      data to verify

    • signature: Buffer

      signature that signed by private key

    • hashAlgorithm: string

      hash algorithm, such as 'sha256', 'sha1'

    Returns boolean

Static addVerifier

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

    PublicKey.addVerifier(getOID('Ed25519'), function (this: PublicKey, data: Buffer, signature: Buffer): boolean {
      return ed25519.detached.verify(data, signature, this.keyRaw)
    })

    Parameters

    • oid: string

      algorithm object identifier

    • fn: Verifier

      Verifier function

    Returns void

Static fromPEM

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

    Parameters

    • pem: Buffer

      PEM formatted buffer

    Returns PublicKey

Generated using TypeDoc