Key Creation
Create a cryptographic key pair based on supported algorithm using the walt.id crypto lib.
Creating a local key
import id.walt.crypto.keys.KeyType
import id.walt.crypto.keys.jwk.JWKKey
import id.walt.crypto.keys.jwk.JWKKeyMetadata
suspend fun main() {
val jwkKey = JWKKey.generate(KeyType.RSA, JWKKeyMetadata())
println("Key ID: " + jwkKey.getKeyId())
}
The JWKKey.generate()
method from the JWKKeyCreator
creates a new key pair based on a given
KeyType
and metadata (provided via the JWKKeyMetadata
object).
Supported Key Types: Ed25519
, secp256k1
, secp256r1
, RSA
You can also optionally provide a keySize
via the JWKKeyMetadata
object to modify the size of the key in bits.
When not provided, the library choose a default. Like so:
suspend fun main() {
val localKey = JWKKey.generate(KeyType.RSA, JWKKeyMetadata(2048))
println("Key ID: " + localKey.getKeyId())
}