signWith

suspend fun signWith(algorithm: SigningAlgorithm, registry: JwtProcessorRegistry, keyId: String? = null): JwtInstance.Jws(source)

Looks up the private key from registry and builds a JWS compact serialization.

The registry is searched using algorithm and keyId as the look-up criteria (see DefaultJwtProcessorRegistry for the full look-up order). If no matching key is found an IllegalStateException is thrown.

Passing co.touchlab.kjwt.model.algorithm.SigningAlgorithm.None delegates directly to build (unsecured token) without consulting the registry.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the signing algorithm to use

registry

the registry to look up the JwsSigner processor

keyId

optional key ID used for registry look-up and embedded in the JWT header's kid field. Defaults to null.

See also

Throws

if no signing key for algorithm (and keyId) is found in registry


suspend fun signWith(integrityProcessor: JwsSigner, keyId: String? = integrityProcessor.keyId): JwtInstance.Jws(source)

Suspends, signs the token using the given JwsSigner, and returns the JWS compact serialization.

The signer is responsible for the signing operation; no registry look-up is performed. The kid header parameter is set to keyId when provided.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

integrityProcessor

the JwsSigner that performs the signing operation

keyId

optional key ID to embed in the JWT header's kid field. Defaults to JwsSigner.keyId.

See also