Sign Content
Sign any type of content using cryptographic key pairs based on supported algorithms from the walt.id crypto lib.
Sign Raw Plaintext
Here is how you can sign raw plaintext with a JWKKey:
import id.walt.crypto.keys.JWKKey
import java.nio.charset.StandardCharsets
suspend fun main() {
val plaintext = "message to sign".toByteArray(StandardCharsets.UTF_8)
val signedContent = jwkKey.signRaw(plaintext)
println("Signed Content: " + signedContent.toString(StandardCharsets.UTF_8))
}
Sign JWS
You can also sign a plaintext message with additional headers, creating a full JWS (JSON Web Signature). See the below usage:
import id.walt.crypto.keys.JWKKey
import java.nio.charset.StandardCharsets
suspend fun main() {
val plaintext = "message to sign".toByteArray(StandardCharsets.UTF_8)
val headers = mapOf("header1" to "value1", "header2" to "value2")
val signedJws = jwkKey.signJws(plaintext, headers)
println("Signed JWS: $signedJws")
}
In each case, replace jwkKey with the actual instance of your JWKKey object. Refer to key creation or import to get a jwkKey object.
Note: Signing functions are suspendable, so make sure they're called from a coroutine scope or from another suspend function.