Key Import
Import cryptographic key pairs based on supported algorithm using the walt.id crypto lib.
Importing Public Key
If you have an existing public key (in raw format), you can import it with the importRawPublicKey
method reference below:
import id.walt.crypto.keys.KeyType
import id.walt.crypto.keys.jwk.JWKKey
import id.walt.crypto.keys.jwk.JWKKeyMetadata
suspend fun main() {
val rawPublicKey: ByteArray = // Your raw public key here
val importedKey = JWKKey.importRawPublicKey( KeyType.RSA, rawPublicKey, JWKKeyMetadata(2048) )
println( "Imported Key ID: " + importedKey.getKeyId() )
}
Importing Keys From JWK and PEM
Similarly, you can import keys from JWK and PEM format using the importJWK(jwk: String) and importPEM(pem: String) methods respectively.
import id.walt.crypto.keys.JWKKey
suspend fun main() {
val jwk: String = // Your JWK string here
val pem: String = // Your PEM string here
val importedJWK = JWKKey.importJWK( jwk )
val importedPEM = JWKKey.importPEM( pem )
println( "JWK Key ID: " + importedJWK.getOrThrow().getKeyId() )
println( "PEM Key ID: " + importedPEM.getOrThrow().getKeyId() )
}