generateKey
open suspend override fun generateKey(algorithm: Algorithm, options: Map<String, Any?> = emptyMap()): GenerateKeyResult
Generates a new cryptographic key.
Returns a GenerateKeyResult for type-safe error handling.
Example Usage:
when (val result = kms.generateKey(Algorithm.Ed25519)) {
is GenerateKeyResult.Success -> {
val handle = result.keyHandle
// Use key handle
}
is GenerateKeyResult.Failure.UnsupportedAlgorithm -> {
// Algorithm not supported
println("Algorithm not supported. Supported: ${result.supportedAlgorithms}")
}
is GenerateKeyResult.Failure.InvalidOptions -> {
// Invalid options provided
println("Invalid options: ${result.reason}")
}
is GenerateKeyResult.Failure.Error -> {
// Unexpected error
println("Error: ${result.reason}")
}
}Content copied to clipboard
Return
Result containing the key handle or failure information
Parameters
algorithm
The algorithm to use
options
Additional options for key generation