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) {
}
});
}
Aggregations