JwkToKey()

edit

Converts a JWK (JSON Web Key) back into a usable key object for signing or verification.

Accepts a struct or JSON string. Typically used after loading keys from an OAuth/OIDC provider's JWKS endpoint.

Requires Extension: Crypto Extension

JwkToKey( jwk=any );

Returns: any

Argument Description
jwk
any, required
edit

JWK as a struct or JSON string

Examples

edit
// Convert a JWK (JSON Web Key) back into a Java key object for signing/verification
// Accepts a struct or a JSON string

// Roundtrip: generate key pair -> export to JWK -> import back kp = GenerateKeyPair( "RSA" ); jwk = KeyToJwk( kp.public ); publicKey = JwkToKey( jwk );
// Use the imported key to verify a JWT token = JwtSign( { sub: "user123" }, kp.private ); claims = JwtVerify( token, publicKey ); // claims.sub == "user123"
// Also accepts a JSON string directly json = serializeJSON( jwk ); publicKey = JwkToKey( json );
// Works with EC and Ed25519 keys too ecKp = GenerateKeyPair( "P-256" ); ecJwk = KeyToJwk( ecKp.public ); ecPublicKey = JwkToKey( ecJwk );

See also