Class CertificateUtils

Utilities for managing certificates and keys.

Constructor Summary 

ConstructorDescription
CertificateUtils()

Method Summary 

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.

Methods inherited from class Object 

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

Constructor Details 

CertificateUtils() 

CertificateUtils()


Method Details 

getCertificate(CertificateRef) 

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

getCertificate(KeyRef) 

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

getEncodedCertificate(CertificateRef) 

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

getEncodedPublicKey(CertificateRef) 

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

parseEncodedCertificate(String) 

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

parseEncodedPublicKey(String, String) 

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

parsePublicKeyFromJWK(String) 

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

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!