Class HibernatePBEBigIntegerEncryptor

Object
org.jasypt.hibernate6.encryptor.HibernatePBEBigIntegerEncryptor

public final class HibernatePBEBigIntegerEncryptor extends Object

Placeholder class for PBEBigIntegerEncryptor objects which are eligible for use from Hibernate.

This class acts as a wrapper on a PBEBigIntegerEncryptor, allowing to be set a registered name (see setRegisteredName(String)) and performing the needed registry operations against the HibernatePBEEncryptorRegistry.

It is not mandatory that a PBEBigIntegerEncryptor be explicitly set with setEncryptor(PBEBigIntegerEncryptor). If not, a StandardPBEBigIntegerEncryptor object will be created internally and it will be configurable with the setPassword(String)/setPasswordCharArray(char[]), setAlgorithm(String), setKeyObtentionIterations(int), setSaltGenerator(SaltGenerator), setIvGenerator(IvGenerator) and setConfig(PBEConfig) methods.

This class is mainly intended for use from Spring Framework or some other IoC container (if you are not using a container of this kind, please see HibernatePBEEncryptorRegistry). The steps to be performed are the following:

  1. Create an object of this class (declaring it).
  2. Set its registeredName and, either its wrapped encryptor or its password, algorithm, keyObtentionIterations, saltGenerator, ivGenerator and config properties.
  3. Declare a typedef in a Hibernate mapping giving its encryptorRegisteredName parameter the same value specified to this object in registeredName.

This in a Spring config file would look like:

 
  ...
  <-- Optional, as the hibernateEncryptor could be directly set an     -->
  <-- algorithm and password.                                          -->
  <bean id="bigIntegerEncryptor"
    class="org.jasypt.encryption.pbe.StandardPBEBigIntegerEncryptor">
    <property name="algorithm">
        <value>PBEWithMD5AndDES</value>
    </property>
    <property name="password">
        <value>XXXXX</value>
    </property>
  </bean>
  
  <bean id="hibernateEncryptor"
    class="org.jasypt.hibernate.encryptor.HibernatePBEBigIntegerEncryptor">
    <property name="registeredName">
        <value>myHibernateBigIntegerEncryptor</value>
    </property>
    <property name="encryptor">
        <ref bean="bigIntegerEncryptor" />
    </property>
  </bean>
  ...
 

And then in the Hibernate mapping file:

    <typedef name="encrypted" class="org.jasypt.hibernate.type.EncryptedBigIntegerType">
      <param name="encryptorRegisteredName">myHibernateBigIntegerEncryptor</param>
    </typedef>
 

An important thing to note is that, when using HibernatePBEBigIntegerEncryptor objects this way to wrap PBEBigIntegerEncryptors, it is not necessary to deal with HibernatePBEEncryptorRegistry, because HibernatePBEBigIntegerEncryptor objects get automatically registered in the encryptor registry when their setRegisteredName(String) method is called.

Since:
1.9.0
Author:
Chus Picos