InMemoryKeyManager

A class for managing cryptographic keys in-memory.

InMemoryKeyManager is an implementation of KeyManager that stores keys in-memory using a mutable map. It provides methods to:

Example Usage:

val keyManager = InMemoryKeyManager()
val keyID = keyManager.generatePrivateKey(JWSAlgorithm.EdDSA, Curve.Ed25519)
val publicKey = keyManager.getPublicKey(keyID)

Notes:

  • Keys are stored in an in-memory mutable map and will be lost once the application is terminated or the object is garbage-collected.

  • It is suitable for testing or scenarios where persistent storage of keys is not necessary.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open override fun exportKey(keyId: String): Jwk

ExportKey exports the key specific by the key ID from the KeyManager.

Link copied to clipboard
open override fun generatePrivateKey(algorithmId: AlgorithmId, options: KeyGenOptions?): String

Generates a private key using specified algorithmId, and stores it in the in-memory keyStore.

Link copied to clipboard
open override fun getDeterministicAlias(publicKey: Jwk): String

Return the alias of publicKey, as was originally returned by generatePrivateKey.

Link copied to clipboard
open override fun getPublicKey(keyAlias: String): Jwk

Computes and returns a public key corresponding to the private key identified by the provided keyAlias.

Link copied to clipboard
open override fun importKey(jwk: Jwk): String

ImportKey imports the key into the KeyManager and returns the key alias.

Link copied to clipboard
open override fun sign(keyAlias: String, signingInput: ByteArray): ByteArray

Signs a payload using the private key identified by the provided keyAlias.