Search in sources :

Example 1 with PBEStringEncryptor

use of org.jasypt.encryption.pbe.PBEStringEncryptor in project cloudbreak by hortonworks.

the class EncryptedStringConfig method register.

@PostConstruct
public void register() {
    HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
    registry.registerPBEStringEncryptor("hibernateStringEncryptor", new PBEStringEncryptor() {

        @Override
        public String encrypt(String message) {
            StringEncryptor encryptor = (StringEncryptor) applicationContext.getBean("PBEStringCleanablePasswordEncryptor");
            return encryptor.encrypt(message);
        }

        @Override
        public String decrypt(String encryptedMessage) {
            StringEncryptor encryptor = (StringEncryptor) applicationContext.getBean("PBEStringCleanablePasswordEncryptor");
            try {
                return encryptor.decrypt(encryptedMessage);
            } catch (EncryptionOperationNotPossibleException e) {
                StringEncryptor legacyEncryptor = (StringEncryptor) applicationContext.getBean("LegacyPBEStringCleanablePasswordEncryptor");
                try {
                    return legacyEncryptor.decrypt(encryptedMessage);
                } catch (EncryptionOperationNotPossibleException ignored) {
                    return encryptedMessage;
                }
            }
        }

        @Override
        public void setPassword(String password) {
        }
    });
}
Also used : EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) PBEStringEncryptor(org.jasypt.encryption.pbe.PBEStringEncryptor) PBEStringEncryptor(org.jasypt.encryption.pbe.PBEStringEncryptor) StringEncryptor(org.jasypt.encryption.StringEncryptor) HibernatePBEEncryptorRegistry(org.jasypt.hibernate4.encryptor.HibernatePBEEncryptorRegistry) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PostConstruct (javax.annotation.PostConstruct)1 StringEncryptor (org.jasypt.encryption.StringEncryptor)1 PBEStringEncryptor (org.jasypt.encryption.pbe.PBEStringEncryptor)1 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)1 HibernatePBEEncryptorRegistry (org.jasypt.hibernate4.encryptor.HibernatePBEEncryptorRegistry)1