Skip to content

certificateFingerprint ​

certificateFingerprint ​

Compute a certificate fingerprint — a hash over the DER encoding.

The certificate is parsed (validating the input and, for PEM, decoding it to DER) before hashing, so the digest is always taken over the canonical DER of a well-formed certificate. Malformed input throws, matching the other DER/PEM boundaries in the library.

Asynchronous: hashing uses WebCrypto's crypto.subtle.digest. Await the returned promise before reading bytes, hex, or colonHex.

ts
function certificateFingerprint(
	certificate: CertificateFingerprintSource,
	algorithm: CertificateFingerprintAlgorithm,
): Promise<CertificateFingerprint>

Parameters

Examples

ts
const fingerprint = await certificateFingerprint(pemString);
console.log(fingerprint.colonHex); // "AB:CD:…" — matches `openssl x509 -fingerprint -sha256`
ts
// Reuse an already-parsed certificate and request SHA-1.
const parsed = parseCertificatePemOrThrow(pemString);
const legacy = await certificateFingerprint(parsed, 'SHA-1');
console.log(legacy.hex);

Released under the MIT License.