org.jasypt.encryption.pbe.PBEStringEncryptor Java Examples

The following examples show how to use org.jasypt.encryption.pbe.PBEStringEncryptor. 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
Source File: DefaultSystemSettingManager.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 File: HibernatePBEStringEncryptor.java    From jasypt with 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 #3
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 File: HibernatePBEEncryptorRegistry.java    From jasypt with 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 File: EncryptorFactoryBean.java    From jasypt with 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 #6
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #7
Source File: HibernatePBEEncryptorRegistry.java    From jasypt with 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 #8
Source File: HibernatePBEEncryptorRegistry.java    From jasypt with 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 #9
Source File: EncryptorFactoryBean.java    From jasypt with 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 #10
Source File: HibernatePBEEncryptorRegistry.java    From jasypt with 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 #11
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #12
Source File: CryptoV1_1.java    From azkaban-plugins with 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 #13
Source File: EncryptorFactoryBean.java    From jasypt with 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 #14
Source File: AbstractEncryptedAsStringType.java    From jasypt with 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 #15
Source File: EncryptedPasswordDriverManagerConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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 #16
Source File: CryptoV1.java    From azkaban-plugins with Apache License 2.0 4 votes vote down vote up
/**
 * DES algorithm
 * @param passphrase
 * @return
 */
private PBEStringEncryptor newEncryptor(String passphrase) {
  StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
  encryptor.setPassword(passphrase);
  return encryptor;
}
 
Example #17
Source File: EncryptedPasswordC3P0ConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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 #18
Source File: StoredConfigService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setTextEncryptor(PBEStringEncryptor textEncryptor) {
    this.textEncryptor = textEncryptor;
}
 
Example #19
Source File: StoredConfigService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void setTextEncryptor(PBEStringEncryptor textEncryptor) {
    this.textEncryptor = textEncryptor;
}
 
Example #20
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #21
Source File: AbstractEncryptedAsStringType.java    From jasypt with 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 File: EncryptedPasswordDriverManagerConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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 #23
Source File: EncryptedPasswordC3P0ConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #25
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #26
Source File: EncryptedPasswordC3P0ConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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 #27
Source File: EncryptedPasswordDriverManagerConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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 #28
Source File: AbstractEncryptedAsStringType.java    From jasypt with 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 #29
Source File: HibernatePBEStringEncryptor.java    From jasypt with 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 #30
Source File: EncryptedPasswordC3P0ConnectionProvider.java    From jasypt with Apache License 2.0 4 votes vote down vote up
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);
   
}