Class JpaCryptoEngine

  • All Implemented Interfaces:
    CryptoEngine

    public class JpaCryptoEngine
    extends DatabaseBackedCryptoEngine
    Implementation of CryptoEngine that extends from DatabaseBackedCryptoEngine and stores its data in a relational database using JPA. It needs a EntityManagerFactory to operate. This class will manage its own transactions. Therefore, it doesn't need any type of transaction manager, and EntityManagerFactory must have the RESOURCE_LOCAL transaction type.

    This class by itself doesn't do any key caching. If this is required, applications may configure a second-level cache on the EntityManagerFactory.

    • Constructor Detail

      • JpaCryptoEngine

        public JpaCryptoEngine​(jakarta.persistence.EntityManagerFactory emf)
        Creates a new JpaCryptoEngine. Will use DefaultKeyEntity as the class to store key entities.
        Parameters:
        emf - the EntityManagerFactory to use.
      • JpaCryptoEngine

        public JpaCryptoEngine​(jakarta.persistence.EntityManagerFactory emf,
                               Class<? extends KeyEntity> entityClass)
        Creates a new JpaCryptoEngine for a custom entity class.
        Parameters:
        emf - the EntityManagerFactory to use.
        entityClass - the entity used to store key information
    • Method Detail

      • getKey

        public SecretKey getKey​(String id)
        Description copied from interface: CryptoEngine
        Retrieves the key for a given id.
        Parameters:
        id - the id of the SecretKey
        Returns:
        the existing SecretKey associated with the id, or null if no such key exists
      • deleteKey

        public void deleteKey​(String id)
        Description copied from interface: CryptoEngine
        Deletes the key for a given id. Does nothing if the key doesn't exist.
        Parameters:
        id - the id of the SecretKey
      • entityClass

        protected Class<? extends KeyEntity> entityClass()
        Provides access to the entity class specified in the constructor; made protected to make this information available to subclasses
        Returns:
        the entity class