Class CertificateUtils

Utilities for managing certificates and keys.

ConstructorDescription
CertificateUtils()
MethodDescription
static getCertificate(CertificateRef)Gets the certificate from the given certificate reference.
static getCertificate(KeyRef)Gets the public certificate from the given private key reference.
static getEncodedCertificate(CertificateRef)Encode the certificate to the base64-encoded DER format.
static getEncodedPublicKey(CertificateRef)Gets the public key from the given certificate reference.
static parseEncodedCertificate(String)Parse the certificate from the base64-encoded DER format.
static parseEncodedPublicKey(String, String)Parse the public key from the given key in X.509 SubjectPublicKeyInfo format.
static parsePublicKeyFromJWK(String)Parse the public key from the given base64-encoded JWK string.

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

CertificateUtils()


static getCertificate(certificateRef: CertificateRef): X509Certificate

Gets the certificate from the given certificate reference.

Parameters:

  • certificateRef - the certificate reference

Returns:

  • The X509Certificate

Throws:

  • Exception - if the reference is invalid or does not refer to an X.509 certificate

static getCertificate(keyRef: KeyRef): X509Certificate

Gets the public certificate from the given private key reference.

Parameters:

  • keyRef - the key reference

Returns:

  • The X509Certificate

Throws:

  • Exception - if the reference is invalid or there is no X.509 certificate

static getEncodedCertificate(certificateRef: CertificateRef): String

Encode the certificate to the base64-encoded DER format.

Parameters:

  • certificateRef - the certificate to encode

Returns:

  • base64-encoded DER certificate

static getEncodedPublicKey(certificateRef: CertificateRef): String

Gets the public key from the given certificate reference.

It is exported in the standard X.509 SubjectPublicKeyInfo format and base64-encoded.

Parameters:

  • certificateRef - the certificate reference with the public key to encode

Returns:

  • The encoded public key

static parseEncodedCertificate(certificate: String): CertificateRef

Parse the certificate from the base64-encoded DER format.

Parameters:

  • certificate - The encoded certificate

Returns:

  • Reference to the parsed certificate

static parseEncodedPublicKey(algorithm: String, encodedKey: String): CertificateRef

Parse the public key from the given key in X.509 SubjectPublicKeyInfo format.

The resulting reference contains only the public key. It can be used for cryptographic operations, but not anything that requires the full certificate.

Parameters:

  • algorithm - The public key algorithm, either EC or RSA
  • encodedKey - The encoded key

Returns:

  • Reference to the public key

static parsePublicKeyFromJWK(jwk: String): CertificateRef

Parse the public key from the given base64-encoded JWK string.

This returns the public key portion of the JWK, not the x5c certificate chain.

Only RSA and EC keys are supported.

The resulting reference contains only the public key. It can be used for cryptographic operations, but not anything that requires the full certificate.

Parameters:

  • jwk - Encoded JWK

Returns:

  • Reference to the public key