DEV Community

Karan Yadav
Karan Yadav

Posted on Originally published at nandai.org

RFC 7638 JWK Cryptographic Key Thumbprints and macOS Keychain Direct-TLS Without Cloud Key Escrow

Two identical RSA, EC, or Ed25519 JSON Web Keys (JWK) routinely serialize to different byte sequences—simply because optional fields like kid, use, whitespace indentation, or key property ordering changed across tools. Naive raw-JSON SHA-256 hashes break immediately across language boundaries.

IETF RFC 7638 solves public-key identification cleanly by hashing only the canonical mathematical parameters in strict UTF-8 lexicographical order. Pairing deterministic key thumbprints locally with macOS Keychain credential storage and direct TLS 1.3 connections lets desktop software authenticate upstream endpoints cleanly without ever sending user API keys to a middleman database.


1. Computing RFC 7638 JWK Canonical SHA-256 Thumbprints

Under RFC 7638 Section 3, you extract strictly the required members for the key type (kty), sort member names lexicographically (EC: ["crv","kty","x","y"], OKP: ["crv","kty","x"], RSA: ["e","kty","n"]), serialize JSON with zero whitespace, hash with SHA-256, and Base64URL-encode without padding:

export async function computeRfc7638Thumbprint(jwk: Record<string, string>): Promise<string> {
  let ordered: Record<string, string>;
  if (jwk.kty === 'EC') {
    ordered = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
  } else if (jwk.kty === 'OKP') {
    ordered = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
  } else if (jwk.kty === 'RSA') {
    ordered = { e: jwk.e, kty: jwk.kty, n: jwk.n };
  } else {
    throw new Error(`Unsupported JWK kty: ${jwk.kty}`);
  }
  const canonical = JSON.stringify(ordered);
  const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical));
  return btoa(String.fromCharCode(...new Uint8Array(digest)))
    .replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=+$/, '');
}
Enter fullscreen mode Exit fullscreen mode

Because crypto.subtle computes the digest inside native browser C++/ARM64 instructions with zero server transmission, you get an unambiguous Base64URL jkt identifier directly in client memory. Review the complete definition and test vectors at nandai.org/glossary/rfc-7638-jwk-cryptographic-key-thumbprint.


2. Eliminating Cloud Key Escrow via macOS Keychain & Direct TLS 1.3

Just as public keys verify deterministically without third-party registries, private BYOK tokens and OAuth 2.0 S256 PKCE credentials never need to sit inside a vendor cloud proxy database:

  • Seal customer credentials locally inside macOS Keychain (kSecAttrAccessibleWhenUnlockedThisDeviceOnly).
  • Open direct TLS 1.3 sockets straight from the workstation to the provider only when the user invokes a remote model or data feed—eliminating proxy token markups and multi-tenant credential leaks.

Read the full architecture and anti-pattern comparison at nandai.org/patterns/zero-vendor-key-escrow-keychain-direct-tls-pattern.


3. Auditing Headers, Keys & Package Supply Chains Locally

For inspecting HTTP CSP/HSTS headers, vendor contracts, and dependency manifests in browser RAM alongside cryptographic checks, open nandai.org/security-engine, or install the notarized 271 MB Apple Silicon desktop suite at nandai.org/download.

Top comments (0)