Java Code Examples for org.jasypt.encryption.pbe.PBEStringEncryptor

The following examples show how to use org.jasypt.encryption.pbe.PBEStringEncryptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public DefaultSystemSettingManager( SystemSettingStore systemSettingStore,
    @Qualifier( "tripleDesStringEncryptor" ) PBEStringEncryptor pbeStringEncryptor, CacheProvider cacheProvider,
    Environment environment, List<String> flags )
{
    checkNotNull( systemSettingStore );
    checkNotNull( pbeStringEncryptor );
    checkNotNull( cacheProvider );
    checkNotNull( environment );
    checkNotNull( flags );

    this.systemSettingStore = systemSettingStore;
    this.pbeStringEncryptor = pbeStringEncryptor;
    this.cacheProvider = cacheProvider;
    this.environment = environment;
    this.flags = flags;
}
 
Example 2
Source Project: jasypt   Source File: EncryptorFactoryBean.java    License: Apache License 2.0 5 votes vote down vote up
public Class<?> getObjectType() {
    if (this.encryptorType == ENCRYPTOR_TYPE_BYTE) {
        return PBEByteEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_STRING) {
        return PBEStringEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_DECIMAL) {
        return PBEBigDecimalEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_INTEGER) {
        return PBEBigIntegerEncryptor.class;
    } else {
        throw new IllegalArgumentException("Unknown encryptor type: " + this.encryptorType);
    }
}
 
Example 3
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the <tt>PBEStringEncryptor</tt> to be held (wrapped) by this
 * object. This method is optional and can be only called once.
 * 
 * @param encryptor the encryptor.
 */
public synchronized void setEncryptor(final PBEStringEncryptor encryptor) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    this.encryptor = encryptor;
    this.encryptorSet = true;
}
 
Example 4
Source Project: jasypt   Source File: HibernatePBEEncryptorRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the <tt>PBEStringEncryptor</tt> registered with the specified
 * name (if exists).
 * 
 * @param registeredName the name with which the desired encryptor was 
 *        registered.
 * @return the encryptor, or null if no encryptor has been registered with
 *         that name.
 */
public synchronized PBEStringEncryptor getPBEStringEncryptor(
        final String registeredName) {
    final HibernatePBEStringEncryptor hibernateEncryptor = 
        (HibernatePBEStringEncryptor) this.stringEncryptors.get(registeredName);
    if (hibernateEncryptor == null) {
        return null;
    }
    return hibernateEncryptor.getEncryptor();
}
 
Example 5
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the <tt>PBEStringEncryptor</tt> to be held (wrapped) by this
 * object. This method is optional and can be only called once.
 * 
 * @param encryptor the encryptor.
 */
public synchronized void setEncryptor(final PBEStringEncryptor encryptor) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    this.encryptor = encryptor;
    this.encryptorSet = true;
}
 
Example 6
Source Project: jasypt   Source File: HibernatePBEEncryptorRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the <tt>PBEStringEncryptor</tt> registered with the specified
 * name (if exists).
 * 
 * @param registeredName the name with which the desired encryptor was 
 *        registered.
 * @return the encryptor, or null if no encryptor has been registered with
 *         that name.
 */
public synchronized PBEStringEncryptor getPBEStringEncryptor(
        final String registeredName) {
    final HibernatePBEStringEncryptor hibernateEncryptor = 
        (HibernatePBEStringEncryptor) this.stringEncryptors.get(registeredName);
    if (hibernateEncryptor == null) {
        return null;
    }
    return hibernateEncryptor.getEncryptor();
}
 
Example 7
Source Project: jasypt   Source File: EncryptorFactoryBean.java    License: Apache License 2.0 5 votes vote down vote up
public Class<?> getObjectType() {
    if (this.encryptorType == ENCRYPTOR_TYPE_BYTE) {
        return PBEByteEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_STRING) {
        return PBEStringEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_DECIMAL) {
        return PBEBigDecimalEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_INTEGER) {
        return PBEBigIntegerEncryptor.class;
    } else {
        throw new IllegalArgumentException("Unknown encryptor type: " + this.encryptorType);
    }
}
 
Example 8
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the <tt>PBEStringEncryptor</tt> to be held (wrapped) by this
 * object. This method is optional and can be only called once.
 * 
 * @param encryptor the encryptor.
 */
public synchronized void setEncryptor(final PBEStringEncryptor encryptor) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    this.encryptor = encryptor;
    this.encryptorSet = true;
}
 
Example 9
Source Project: jasypt   Source File: HibernatePBEEncryptorRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the <tt>PBEStringEncryptor</tt> registered with the specified
 * name (if exists).
 * 
 * @param registeredName the name with which the desired encryptor was 
 *        registered.
 * @return the encryptor, or null if no encryptor has been registered with
 *         that name.
 */
public synchronized PBEStringEncryptor getPBEStringEncryptor(
        final String registeredName) {
    final HibernatePBEStringEncryptor hibernateEncryptor = 
        (HibernatePBEStringEncryptor) this.stringEncryptors.get(registeredName);
    if (hibernateEncryptor == null) {
        return null;
    }
    return hibernateEncryptor.getEncryptor();
}
 
Example 10
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the <tt>PBEStringEncryptor</tt> to be held (wrapped) by this
 * object. This method is optional and can be only called once.
 * 
 * @param encryptor the encryptor.
 */
public synchronized void setEncryptor(final PBEStringEncryptor encryptor) {
    if (this.encryptorSet) {
        throw new EncryptionInitializationException(
                "An encryptor has been already set: no " +
                "further configuration possible on hibernate wrapper");
    }
    this.encryptor = encryptor;
    this.encryptorSet = true;
}
 
Example 11
Source Project: jasypt   Source File: HibernatePBEEncryptorRegistry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the <tt>PBEStringEncryptor</tt> registered with the specified
 * name (if exists).
 * 
 * @param registeredName the name with which the desired encryptor was 
 *        registered.
 * @return the encryptor, or null if no encryptor has been registered with
 *         that name.
 */
public synchronized PBEStringEncryptor getPBEStringEncryptor(
        final String registeredName) {
    final HibernatePBEStringEncryptor hibernateEncryptor = 
        (HibernatePBEStringEncryptor) this.stringEncryptors.get(registeredName);
    if (hibernateEncryptor == null) {
        return null;
    }
    return hibernateEncryptor.getEncryptor();
}
 
Example 12
Source Project: jasypt   Source File: EncryptorFactoryBean.java    License: Apache License 2.0 5 votes vote down vote up
public Class<?> getObjectType() {
    if (this.encryptorType == ENCRYPTOR_TYPE_BYTE) {
        return PBEByteEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_STRING) {
        return PBEStringEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_DECIMAL) {
        return PBEBigDecimalEncryptor.class;
    } else if (this.encryptorType == ENCRYPTOR_TYPE_BIG_INTEGER) {
        return PBEBigIntegerEncryptor.class;
    } else {
        throw new IllegalArgumentException("Unknown encryptor type: " + this.encryptorType);
    }
}
 
Example 13
Source Project: azkaban-plugins   Source File: CryptoV1_1.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * AES algorithm
 * @param passphrase
 * @return
 */
private PBEStringEncryptor newEncryptor(String passphrase) {
  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  encryptor.setPassword(passphrase);
  encryptor.setProvider(PROVIDER);
  encryptor.setAlgorithm(CRYPTO_ALGO);
  return encryptor;
}
 
Example 14
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 4 votes vote down vote up
HibernatePBEStringEncryptor(final String registeredName, 
        final PBEStringEncryptor encryptor) {
    this.encryptor = encryptor;
    this.registeredName = registeredName;
    this.encryptorSet = true;
}
 
Example 15
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(AvailableSettings.DRIVER);
   final String url = props.getProperty(AvailableSettings.URL);
   final String user = props.getProperty(AvailableSettings.USER);
   final String password = props.getProperty(AvailableSettings.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               AvailableSettings.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               AvailableSettings.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               AvailableSettings.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               AvailableSettings.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate do the rest
   super.configure(props);
   
}
 
Example 16
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(AvailableSettings.DRIVER);
   final String url = props.getProperty(AvailableSettings.URL);
   final String user = props.getProperty(AvailableSettings.USER);
   final String password = props.getProperty(AvailableSettings.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               AvailableSettings.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               AvailableSettings.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               AvailableSettings.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               AvailableSettings.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate process
   super.configure(props);
   
}
 
Example 17
Source Project: jasypt   Source File: AbstractEncryptedAsStringType.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 18
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 4 votes vote down vote up
HibernatePBEStringEncryptor(final String registeredName, 
        final PBEStringEncryptor encryptor) {
    this.encryptor = encryptor;
    this.registeredName = registeredName;
    this.encryptorSet = true;
}
 
Example 19
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(AvailableSettings.DRIVER);
   final String url = props.getProperty(AvailableSettings.URL);
   final String user = props.getProperty(AvailableSettings.USER);
   final String password = props.getProperty(AvailableSettings.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               AvailableSettings.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               AvailableSettings.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               AvailableSettings.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               AvailableSettings.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate do the rest
   super.configure(props);
   
}
 
Example 20
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(AvailableSettings.DRIVER);
   final String url = props.getProperty(AvailableSettings.URL);
   final String user = props.getProperty(AvailableSettings.USER);
   final String password = props.getProperty(AvailableSettings.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               AvailableSettings.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               AvailableSettings.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               AvailableSettings.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               AvailableSettings.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate process
   super.configure(props);
   
}
 
Example 21
Source Project: jasypt   Source File: AbstractEncryptedAsStringType.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 22
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 4 votes vote down vote up
HibernatePBEStringEncryptor(final String registeredName, 
        final PBEStringEncryptor encryptor) {
    this.encryptor = encryptor;
    this.registeredName = registeredName;
    this.encryptorSet = true;
}
 
Example 23
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(Environment.DRIVER);
   final String url = props.getProperty(Environment.URL);
   final String user = props.getProperty(Environment.USER);
   final String password = props.getProperty(Environment.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               Environment.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               Environment.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               Environment.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               Environment.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate do the rest
   super.configure(props);
   
}
 
Example 24
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(Environment.DRIVER);
   final String url = props.getProperty(Environment.URL);
   final String user = props.getProperty(Environment.USER);
   final String password = props.getProperty(Environment.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               Environment.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               Environment.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               Environment.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               Environment.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate process
   super.configure(props);
   
}
 
Example 25
Source Project: jasypt   Source File: AbstractEncryptedAsStringType.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 26
Source Project: jasypt   Source File: HibernatePBEStringEncryptor.java    License: Apache License 2.0 4 votes vote down vote up
HibernatePBEStringEncryptor(final String registeredName, 
        final PBEStringEncryptor encryptor) {
    this.encryptor = encryptor;
    this.registeredName = registeredName;
    this.encryptorSet = true;
}
 
Example 27
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(Environment.DRIVER);
   final String url = props.getProperty(Environment.URL);
   final String user = props.getProperty(Environment.USER);
   final String password = props.getProperty(Environment.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               Environment.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               Environment.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               Environment.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               Environment.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate do the rest
   super.configure(props);
   
}
 
Example 28
public void configure(final Properties props) {
   
   final String encryptorRegisteredName = 
       props.getProperty(ParameterNaming.ENCRYPTOR_REGISTERED_NAME);
   
   final HibernatePBEEncryptorRegistry encryptorRegistry =
       HibernatePBEEncryptorRegistry.getInstance();
   final PBEStringEncryptor encryptor = 
       encryptorRegistry.getPBEStringEncryptor(encryptorRegisteredName);
   
   if (encryptor == null) {
       throw new EncryptionInitializationException(
               "No string encryptor registered for hibernate " +
               "with name \"" + encryptorRegisteredName + "\"");
   }

   // Get the original values, which may be encrypted
   final String driver = props.getProperty(Environment.DRIVER);
   final String url = props.getProperty(Environment.URL);
   final String user = props.getProperty(Environment.USER);
   final String password = props.getProperty(Environment.PASS);

   // Perform decryption operations as needed and store the new values
   if (PropertyValueEncryptionUtils.isEncryptedValue(driver)) {
       props.setProperty(
               Environment.DRIVER, 
               PropertyValueEncryptionUtils.decrypt(driver, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(url)) {
       props.setProperty(
               Environment.URL, 
               PropertyValueEncryptionUtils.decrypt(url, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(user)) {
       props.setProperty(
               Environment.USER, 
               PropertyValueEncryptionUtils.decrypt(user, encryptor));
   }
   if (PropertyValueEncryptionUtils.isEncryptedValue(password)) {
       props.setProperty(
               Environment.PASS, 
               PropertyValueEncryptionUtils.decrypt(password, encryptor));
   }
   
   // Let Hibernate process
   super.configure(props);
   
}
 
Example 29
Source Project: jasypt   Source File: AbstractEncryptedAsStringType.java    License: Apache License 2.0 4 votes vote down vote up
protected synchronized final void checkInitialization() {
    
    if (!this.initialized) {
        
        if (this.useEncryptorName) {

            final HibernatePBEEncryptorRegistry registry = 
                HibernatePBEEncryptorRegistry.getInstance();
            final PBEStringEncryptor pbeEncryptor = 
                registry.getPBEStringEncryptor(this.encryptorName);
            if (pbeEncryptor == null) {
                throw new EncryptionInitializationException(
                        "No string encryptor registered for hibernate " +
                        "with name \"" + this.encryptorName + "\"");
            }
            this.encryptor = pbeEncryptor;
            
        } else {
            
            final StandardPBEStringEncryptor newEncryptor = 
                new StandardPBEStringEncryptor();
            
            newEncryptor.setPassword(this.password);
            
            if (this.algorithm != null) {
                newEncryptor.setAlgorithm(this.algorithm);
            }
            
            if (this.providerName != null) {
                newEncryptor.setProviderName(this.providerName);
            }
            
            if (this.keyObtentionIterations != null) {
                newEncryptor.setKeyObtentionIterations(
                        this.keyObtentionIterations.intValue());
            }
            
            if (this.stringOutputType != null) {
                newEncryptor.setStringOutputType(this.stringOutputType);
            }
            
            newEncryptor.initialize();
            
            this.encryptor = newEncryptor;
            
        }
        
        this.initialized = true;
    }
    
}
 
Example 30
Source Project: sakai   Source File: StoredConfigService.java    License: Educational Community License v2.0 4 votes vote down vote up
public void setTextEncryptor(PBEStringEncryptor textEncryptor) {
    this.textEncryptor = textEncryptor;
}