signWith

suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.MACBased, key: HMAC.Key, keyId: String? = null): JwtInstance.Jws(source)

Signs the JWT using an HMAC (HS256/384/512) symmetric key.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the HMAC-based signing algorithm (HS256, HS384, or HS512)

key

the HMAC symmetric key to sign with

keyId

optional key ID to embed in the token header's kid field. Defaults to null.


Signs the JWT using an RSA PKCS#1 (RS256/384/512) private key.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the RSA PKCS#1-based signing algorithm (RS256, RS384, or RS512)

key

the RSA PKCS#1 private key to sign with

keyId

optional key ID to embed in the token header's kid field. Defaults to null.


Signs the JWT using an RSA PSS (PS256/384/512) private key.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the RSA PSS-based signing algorithm (PS256, PS384, or PS512)

key

the RSA PSS private key to sign with

keyId

optional key ID to embed in the token header's kid field. Defaults to null.


Signs the JWT using an ECDSA (ES256/384/512) private key.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the ECDSA-based signing algorithm (ES256, ES384, or ES512)

key

the ECDSA private key to sign with

keyId

optional key ID to embed in the token header's kid field. Defaults to null.


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm, key: Key, keyId: String? = null): JwtInstance.Jws(source)

Signs the JWT using any SigningAlgorithm and raw Key.

Prefer the strongly typed overloads (e.g. signWith accepting HMAC.Key or RSA.PKCS1.PrivateKey) when possible, as they enforce the correct key type at compile time.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

algorithm

the JWS signing algorithm to use

key

the raw cryptography-kotlin key to sign with; must be compatible with algorithm

keyId

optional key ID to embed in the token header's kid field. Defaults to null.


suspend fun JwtBuilder.signWith(key: SigningKey.SigningOnlyKey, keyId: String? = key.identifier.keyId): JwtInstance.Jws(source)

Builds and returns a JWS compact serialization using a pre-built SigningKey.SigningOnlyKey.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

key

the signing key (or key pair) used to produce the signature

keyId

optional key ID to embed in the JWT header's kid field. Defaults to the key ID stored in key's identifier.


suspend fun JwtBuilder.signWith(key: SigningKey.SigningKeyPair, keyId: String? = key.identifier.keyId): JwtInstance.Jws(source)

Builds and returns a JWS compact serialization using a pre-built SigningKey.SigningKeyPair.

Return

the resulting JwtInstance.Jws compact serialization

Parameters

key

the signing key (or key pair) used to produce the signature

keyId

optional key ID to embed in the JWT header's kid field. Defaults to the key ID stored in key's identifier.


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.MACBased, jwk: Jwk.Oct, keyId: String? = jwk.kid, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an HMAC key derived from the given Jwk.Oct symmetric JWK.

Return

the signed JwtInstance.Jws token

Parameters

algorithm

the HMAC-based signing algorithm (HS256, HS384, or HS512)

jwk

the Oct JWK containing the raw symmetric key material

keyId

optional key ID override; when set, it is embedded in the token header's kid field. Defaults to the JWK's own kid field.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.PKCS1Based, jwk: Jwk.Rsa, keyId: String? = jwk.kid, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an RSA PKCS#1 private key derived from the given Jwk.Rsa JWK.

Return

the signed JwtInstance.Jws token

Parameters

algorithm

the RSA PKCS#1-based signing algorithm (RS256, RS384, or RS512)

jwk

the RSA JWK containing the private key parameters

keyId

optional key ID override; when set, it is embedded in the token header's kid field. Defaults to the JWK's own kid field.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.PSSBased, jwk: Jwk.Rsa, keyId: String? = jwk.kid, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an RSA PSS private key derived from the given Jwk.Rsa JWK.

Return

the signed JwtInstance.Jws token

Parameters

algorithm

the RSA PSS-based signing algorithm (PS256, PS384, or PS512)

jwk

the RSA JWK containing the private key parameters

keyId

optional key ID override; when set, it is embedded in the token header's kid field. Defaults to the JWK's own kid field.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.ECDSABased, jwk: Jwk.Ec, keyId: String? = jwk.kid, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an ECDSA private key derived from the given Jwk.Ec JWK.

Return

the signed JwtInstance.Jws token

Parameters

algorithm

the ECDSA-based signing algorithm (ES256, ES384, or ES512)

jwk

the EC JWK containing the private key parameter d

keyId

optional key ID override; when set, it is embedded in the token header's kid field. Defaults to the JWK's own kid field.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.MACBased, key: String, keyFormat: HMAC.Key.Format, keyId: String? = null, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an HMAC algorithm with a key decoded from a String.

Return

the signed JwtInstance.Jws token.

Parameters

algorithm

the HMAC-based signing algorithm (HS256, HS384, or HS512).

key

the HMAC key material encoded as a String.

keyFormat

the format in which key is encoded.

keyId

optional key ID to embed in the token header's kid field. Defaults to null.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.PKCS1Based, key: String, keyFormat: RSA.PrivateKey.Format, keyId: String? = null, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an RSA PKCS#1 algorithm with a private key decoded from a String.

Return

the signed JwtInstance.Jws token.

Parameters

algorithm

the RSA PKCS#1-based signing algorithm (RS256, RS384, or RS512).

key

the RSA private key material encoded as a String.

keyFormat

the format in which key is encoded.

keyId

optional key ID to embed in the token header's kid field. Defaults to null.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.PSSBased, key: String, keyFormat: RSA.PrivateKey.Format, keyId: String? = null, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an RSA PSS algorithm with a private key decoded from a String.

Return

the signed JwtInstance.Jws token.

Parameters

algorithm

the RSA PSS-based signing algorithm (PS256, PS384, or PS512).

key

the RSA private key material encoded as a String.

keyFormat

the format in which key is encoded.

keyId

optional key ID to embed in the token header's kid field. Defaults to null.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default


suspend fun JwtBuilder.signWith(algorithm: SigningAlgorithm.ECDSABased, key: String, keyFormat: EC.PrivateKey.Format, keyId: String? = null, cryptoProvider: CryptographyProvider = CryptographyProvider.Default): JwtInstance.Jws(source)

Signs the JWT using an ECDSA algorithm with a private key decoded from a String.

Return

the signed JwtInstance.Jws token.

Parameters

algorithm

the ECDSA-based signing algorithm (ES256, ES384, or ES512).

key

the EC private key material encoded as a String.

keyFormat

the format in which key is encoded.

keyId

optional key ID to embed in the token header's kid field. Defaults to null.

cryptoProvider

the CryptographyProvider used to decode the key; defaults to CryptographyProvider.Default