Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * =============================================================================
   *   Copyright (c) 2007, The JASYPT team (
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
  *   Unless required by applicable law or agreed to in writing, software
  *   distributed under the License is distributed on an "AS IS" BASIS,
  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *   See the License for the specific language governing permissions and
  *   limitations under the License.
  * =============================================================================
 package org.jasypt.hibernate;

Registry for all the PBEStringEncryptor 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 do with HibernatePBEEncryptor instead.

This registry is a singleton which maintains a registry of PBEStringEncryptor 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 (registerPBEEncryptor(java.lang.String,org.jasypt.encryption.pbe.PBEStringEncryptor)).
  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:

  StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
  HibernatePBEEncryptorRegistry registry =
  registry.registerPBEEncryptor("strongHibernateEncryptor", strongEncryptor);

And then, reference it from a Hibernate mapping file:

    <typedef name="encrypted" class="org.jasypt.hibernate.EncryptedTextType">
      <param name="encryptorRegisteredName">strongHibernateEncryptor</param>

Replaced by org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry and will be removed in version 1.3.
Daniel Fernández Garrido
     // The singleton instance
     private static HibernatePBEEncryptorRegistry instance = 
         new HibernatePBEEncryptorRegistry();
     // Registry map
     private HashMap configs = new HashMap();
Returns the singleton instance of the registry.

the registry.
    public static HibernatePBEEncryptorRegistry getInstance() {
        return ;
    // The registry cannot be externally instantiated.
    private HibernatePBEEncryptorRegistry() { }

Registers a PBEStringEncryptor object with the specified name.

registeredName the registered name.
encryptor the encryptor to be registered.
    public synchronized void registerPBEEncryptor(
            String registeredNamePBEStringEncryptor encryptor) {
        HibernatePBEEncryptor hibernateEncryptor = 
            new HibernatePBEEncryptor(registeredNameencryptor);
    // Not public: this is used from HibernatePBEEncryptor.setRegisteredName.
    synchronized void registerHibernatePBEEncryptor(
            HibernatePBEEncryptor hibernateEncryptor) {
    // Not public: this is used from HibernatePBEEncryptor.setRegisteredName.
    synchronized void unregisterHibernatePBEEncryptor(String name) {

Returns the PBEStringEncryptor registered with the specified name (if exists).

name the name of the desired encryptor.
the encryptor, or null if no encryptor has been registered with that name.
    public synchronized HibernatePBEEncryptor getHibernatePBEEncryptor(
            String name) {
        return (HibernatePBEEncryptor.get(name);
New to GrepCode? Check out our FAQ X