Class HibernatePBEEncryptorRegistry

Object
org.jasypt.hibernate6.encryptor.HibernatePBEEncryptorRegistry

public final class HibernatePBEEncryptorRegistry extends Object

Registry for all the PBE*Encryptor which are eligible for use from Hibernate.

This class is intended to be directly used in applications where an IoC container (like Spring Framework) is not present. If it is, it is better to use the HibernatePBE*Encryptor classes directly, instead.

This registry is a singleton which maintains a registry of PBE*Encryptor objects which can be used from Hibernate, by using its registeredName to reference them from mappings.

The steps would be:

  1. Obtain the registry instance (getInstance()).
  2. Register the encryptor, giving it a registered name (registerPBE*Encryptor(String, PBE*Encryptor).
  3. Declare a typedef in a Hibernate mapping giving its encryptorRegisteredName parameter the same value specified when registering the encryptor.

This is, first register the encryptor (example with a String encryptor):

  StandardPBEStringEncryptor myEncryptor = new StandardPBEStringEncryptor();
  ...
  HibernatePBEEncryptorRegistry registry =
      HibernatePBEEncryptorRegistry.getInstance();
  registry.registerPBEStringEncryptor("myHibernateEncryptor", myEncryptor);
 

And then, reference it from a Hibernate mapping file:

    <typedef name="encryptedString" class="org.jasypt.hibernate.type.EncryptedStringType">
      <param name="encryptorRegisteredName">myHibernateEncryptor</param>
    </typedef>
 

Since:
1.9.0
Author:
Chus Picos