Key Generator
The KeyGenerator
interface provides a blueprint for implementing cryptographic key generation and conversion functionalities for various cryptographic algorithms and key types.
Cryptographic keys play a pivotal role in securing communication and data. This interface standardizes the key management operations including key generation, format conversion, and key derivation, ensuring that implementers adhere to a consistent API. In the realm of cryptographic applications, KeyGenerator
enables developers to instantiate key pairs, convert keys between various formats, and derive public keys from private ones, while abstracting the specifics of the cryptographic algorithm and key type in use.
Implementers are expected to provide concrete implementations for various key management activities for specified algorithms (e.g., RSA, EC) and key types (symmetric/asymmetric), and to handle potential exceptions, especially in scenarios such as deriving public keys in symmetric key contexts.
Example Usage:
val keyGenerator: KeyGenerator = ...
val privateKey: Jwk = keyGenerator.generatePrivateKey()
val publicKey: Jwk = keyGenerator.getPublicKey(privateKey)
val privateKeyBytes: ByteArray = keyGenerator.privateKeyToBytes(privateKey)
val restoredPrivateKey: Jwk = keyGenerator.bytesToPrivateKey(privateKeyBytes)
Note:
For symmetric key generators, certain methods like getPublicKey
or publicKeyToBytes
may not be applicable and should throw an UnsupportedOperationException
.
Inheritors
Functions
Converts a private key as bytes into a Jwk.
Converts a public key as bytes into a Jwk. Applicable for asymmetric Key Generators only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
Derives a public key from the private key provided. Applicable for asymmetric Key Generators only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
Generates a private key.
Converts a private key to bytes.
Converts a public key to bytes. Applicable for asymmetric KeyGenerator implementations only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception