generateKey
abstract suspend 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
open suspend fun generateKey(algorithmName: String, options: Map<String, Any?> = emptyMap()): GenerateKeyResult
Generates a new cryptographic key by algorithm name.
Convenience method that parses the algorithm name and returns a Result.
Return
Result containing the key handle or failure information
Parameters
algorithmName
The algorithm name (e.g., "Ed25519", "secp256k1")
options
Additional options for key generation