To generate a JWT from an X.509 certificate, sign the protected header and claims with the matching private key; the certificate by itself contains no signing secret. A verifier uses the certificate's public key, or a trusted public key mapped to it, to check the signature.
In practice, “generate a JWT from a certificate” usually means using a certificate-backed private key to create an asymmetrically signed JSON Web Signature. The receiver's accepted algorithms, key identifier, issuer, audience, and lifetime rules determine the exact configuration. If the receiver instead expects HS256, it wants a shared secret rather than an X.509 certificate and private key.

Separate certificates, keys, and shared secrets
These credentials look related during development, but they have different roles. Confirm what the target service actually calls its signing credential before loading any key material.
| Credential | What it contains | Role in the JWT workflow |
|---|---|---|
| X.509 certificate | Identity information and a public key | Provides trust context and a public key that can verify a signature |
| Certificate private key | Secret key material used to create signatures | Creates the certificate-backed JWT signature |
| Public key or JWK | A public verification key | Allows a service to verify the JWT without loading the certificate chain |
| Shared secret | The same secret held by the signer and verifier | Supports symmetric algorithms such as HS256, but is not an X.509 certificate |
A certificate and its private key may be distributed separately or bundled in a PKCS#12 container. Either way, the private key must correspond to the certificate's public key. Your PKI tooling should confirm that the public keys derived from both files have matching fingerprints before you attempt to issue a token.
Also distinguish a signing certificate from a TLS client certificate. A client certificate can authenticate a mutual-TLS connection, but it does not automatically sign the application's JWT. The token still needs its own approved signing key and algorithm.
Select an algorithm both sides accept
The key type narrows the options, but the receiver's JOSE policy makes the final decision. Do not select an algorithm merely because the certificate or key supports it. The verifier must be configured to accept the exact algorithm you use.
| Signing key | Common JWT algorithm | Important constraint |
|---|---|---|
| RSA private key | RS256 or PS256 | RS256 uses RSASSA-PKCS1-v1_5 with SHA-256, while PS256 uses RSASSA-PSS with SHA-256; use only what the target allows |
| Elliptic-curve P-256 key | ES256 | The library and receiver must support ECDSA with P-256 and SHA-256 |
| Ed25519 key | EdDSA | The target must support EdDSA with the curve represented by the key |
| Shared symmetric secret | HS256 | No X.509 certificate is involved; signer and verifier share the same secret |
The compact JWS construction is defined in RFC 7515, while the algorithm names and cryptographic requirements are specified in RFC 7518. For a focused comparison of symmetric and asymmetric choices, see Generate a JWT Token Online: HS256 vs RS256.
Generate a certificate-backed JWT
- Confirm the receiver's signing contract. Record the accepted algorithm allowlist, issuer, audience, required lifetime, expected key identifier, and whether the verifier expects the certificate chain in a JWS header. A successful signature does not make a token acceptable if its claims or algorithm violate application policy.
- Prepare the matching certificate and private key. Obtain the X.509 certificate and its corresponding private key from the approved certificate-management process. If they are packaged together, extract or load them through your organization's secure tooling. Keep the private key outside browser inputs, source code, logs, chat messages, and token claims.
- Validate the key pair and select the algorithm. Compare the public keys derived from the certificate and private key, then choose RS256, PS256, ES256, or EdDSA according to the key type and the receiver's allowlist. Reject the workflow if the target supports only HS256, because an X.509 private key is not an HMAC secret.
- Use a maintained JOSE library. Load the private key and signing configuration through the library's supported key-management path. Do not implement base64url encoding, JSON serialization, or HMAC or signature calculation manually when a maintained library already provides those operations.
- Create the claims object. Include authoritative values for iss, aud, and any required sub, jti, iat, nbf, and exp claims. Set the expiration according to the receiver's policy rather than relying on a library default. NumericDate values represent seconds from the Unix epoch, not JavaScript milliseconds.
- Configure the protected header. Set alg to the exact permitted algorithm and typ to JWT. Add kid when the target uses it to select the correct verification key. If a target explicitly requires an x5c certificate-chain header, use a JOSE library that supports it and follow the receiver's chain and size rules; a certificate normally belongs in trust configuration rather than in the claims.
- Create and serialize the signature. The library should UTF-8 encode the header and claims, encode them with unpadded base64url, sign the exact header.payload byte sequence, and return three compact segments separated by periods. Preserve the returned token without adding quotes, whitespace, or line breaks.
- Verify with the target's own policy. Test the copied token with the maintained JOSE library used by the receiving service. Require the intended algorithm, trusted public key or certificate chain, issuer, audience, and lifetime checks. Then test expiration, not-before behavior, clock-skew handling, and any replay controls required by the application.
Use the browser generator for an HS256 secret
The JWT Generator is appropriate only when the receiving service expects HS256 and you have a shared secret, not an X.509 certificate. It fixes the protected header to HS256 and JWT, signs with browser-native HMAC-SHA-256, and produces a compact three-segment token.
- Paste a strict JSON claims object. The input must be a JSON object rather than an array or null. Comments, trailing commas, undefined, NaN, Infinity, and JavaScript expressions are rejected.
- Enter or generate a development secret. Use a secret containing at least 32 UTF-8 bytes. The random control creates 32 cryptographically random bytes and displays them as 64 hexadecimal characters; those 64 characters become the UTF-8 HMAC secret. Character count and byte count differ for non-ASCII text, so validate byte length rather than assuming every 32-character string qualifies.
- Generate and inspect the result. Review the fixed header, the submitted claims, the three segment lengths, and the absence of confidential data. The header and claims use UTF-8 and unpadded base64url encoding. Anyone with the token can decode its header and claims because HS256 signs data without encrypting it.
- Copy and verify the token. Pass the copied token to the target JOSE library with an explicit algorithm, issuer, audience, lifetime, and key policy. The generator does not verify the token it creates, so a successful generation step is not proof that the receiver will accept it.
Claims and key material remain in the current browser tab and are processed with Web Crypto. The tool does not provide persistent key storage, publish a JWK, contact an identity provider, select a kid, or encrypt claims. It also does not add iat, exp, nbf, iss, sub, aud, jti, or any other claim automatically.
Although the random control uses cryptographically secure randomness, its result is displayed in the browser and is not automatically provisioned as a production secret. Use it only with non-production claims. Production secrets should come from the system's secret-management process and be rotated, stored, and audited accordingly.
Verify the signature and the claims
Signature verification and application validation are separate checks. A valid cryptographic signature only proves that the token was produced by the holder of the expected signing key and has not been modified since signing. It does not establish that the token belongs to the intended user, audience, or environment.
- Algorithm: Require the exact expected algorithm and reject a token that asks the verifier to switch to a different one.
- Key trust: Resolve the correct public key through the approved key identifier or certificate mapping, then validate the certificate chain when certificate trust is part of the design.
- Issuer and audience: Compare the token's iss and aud values with values obtained from the application's trusted configuration, not from an untrusted token field.
- Lifetime: Enforce exp and nbf with an explicit clock-skew policy. Remember that JWT NumericDate values use Unix epoch seconds.
- Replay and context: Enforce jti, nonce, audience, or transaction controls when the protocol requires them. Decide whether revocation, introspection, or an external deny list is necessary.
The same secret must be used to sign and verify an HS256 token. Verification with the wrong secret cannot detect the intended signature relationship, and a syntactically valid token can still be expired, mis-scoped, replayed, or otherwise unacceptable.
Protect the key and treat claims as visible
A signed JWT is not an encrypted container. Its header and payload can be decoded by anyone who receives it. Do not place passwords, private keys, personal records, or confidential application data in a JWT merely because the token is signed. If confidentiality is required, use a separate encryption mechanism designed for that purpose.
Treat an active token as a credential when the application uses it as a bearer token. Clipboard history, screenshots, browser extensions, logs, support tickets, and chat messages can disclose it. Avoid pasting a real secret or live token into an environment outside its intended boundary; rotate or revoke it rather than assuming local processing made disclosure harmless.
Production key operations should remain inside the approved secret-management, signing-service, or hardware-backed environment. The browser workflow described here is suitable for development and interoperability testing with non-production material. For production, use a maintained JOSE library so algorithm allowlists, key discovery, rotation, error handling, and application trust rules live beside the rest of the system.
Resolve common signing mismatches
- “Unexpected algorithm” error: Align the signer's alg with the verifier's exact allowlist. Do not switch algorithms only to bypass the error.
- Invalid signature: Check that the certificate and private key match, the algorithm is appropriate for the key, and the token was not changed during copying.
- Expired or not-yet-valid token: Check NumericDate units, expiration policy, issuer clock, verifier clock, and permitted skew.
- Missing issuer or audience: Add the required claims to the original JSON object; the JWT Generator does not insert them for you.
- Certificate recognized but token rejected: Confirm that the certificate is expected for JWT signing rather than only for TLS client authentication, and that the application has not confused public certificate data with a private signing key.