Interface KeyGenerator
-
- All Implemented Interfaces:
public interface KeyGeneratorThe
KeyGeneratorinterface 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,
KeyGeneratorenables 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.
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)For symmetric key generators, certain methods like
getPublicKeyorpublicKeyToBytesmay not be applicable and should throw anUnsupportedOperationException.
-
-
Method Summary
Modifier and Type Method Description abstract JwkgeneratePrivateKey(KeyGenOptions options)Generates a private key. abstract JwkcomputePublicKey(Jwk privateKey)Derives a public key from the private key provided. abstract ByteArrayprivateKeyToBytes(Jwk privateKey)Converts a private key to bytes. abstract ByteArraypublicKeyToBytes(Jwk publicKey)Converts a public key to bytes. abstract JwkbytesToPrivateKey(ByteArray privateKeyBytes)Converts a private key as bytes into a Jwk. abstract JwkbytesToPublicKey(ByteArray publicKeyBytes)Converts a public key as bytes into a Jwk. abstract JwagetAlgorithm()Indicates the algorithm intended to be used with the key. abstract StringgetKeyType()KeyType in String format (OKP, EC, etc.). abstract JwaCurvegetCurve()The curve used for the key generation. -
-
Method Detail
-
generatePrivateKey
abstract Jwk generatePrivateKey(KeyGenOptions options)
Generates a private key.
-
computePublicKey
abstract Jwk computePublicKey(Jwk privateKey)
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
-
privateKeyToBytes
abstract ByteArray privateKeyToBytes(Jwk privateKey)
Converts a private key to bytes.
-
publicKeyToBytes
abstract ByteArray publicKeyToBytes(Jwk publicKey)
Converts a public key to bytes. Applicable for asymmetric KeyGenerator implementations only. Implementers of symmetric key generators should throw an UnsupportedOperation Exception
-
bytesToPrivateKey
abstract Jwk bytesToPrivateKey(ByteArray privateKeyBytes)
Converts a private key as bytes into a Jwk.
-
bytesToPublicKey
abstract Jwk bytesToPublicKey(ByteArray publicKeyBytes)
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
-
getAlgorithm
abstract Jwa getAlgorithm()
Indicates the algorithm intended to be used with the key.
-
getKeyType
abstract String getKeyType()
KeyType in String format (OKP, EC, etc.).
-
-
-
-