Interface KeyGenerator

  • All Implemented Interfaces:

    
    public interface KeyGenerator
    
                        

    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.

    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 getPublicKey or publicKeyToBytes may not be applicable and should throw an UnsupportedOperationException.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • 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

      • 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

      • 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.).