Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jasypt not decrypting already encrypted property (i.e in application.properties file) in xml based configuration spring boot project #378

Open
Udaykumar519 opened this issue Dec 20, 2023 · 3 comments

Comments

@Udaykumar519
Copy link

@ulisesbocchio
I have two spring boot projects, one uses java based configuration and other uses XML based configuration.

We have a new requirement of encrypting properties present in application.properties file.

So, we have tried using jasypt-spring-boot-starter (v3.0.5) and jasypt-maven-plugin (v3.0.5) in both the projects for encryption/decryption.

  1. Encryption is done using mvn plugin command
    mvn jasypt:encrypt "-Djasypt.encryptor.password=pvt-key" "-Djasypt.plugin.path=file:src/main/resources/application.properties"

  2. Property file after encryption
    spring.db.password=ENC(encrypted-password)

  3. Decryption
    For decrypting above property, we used @value annotation provided by spring
    @value("${spring.db.password}")

DECRYPTION is working as expected in project where java based configurations are used.

*But in XML based Configuration project, I am getting ENCRYPTED VALUES only, without any Decryption. [FYI, Even after adding context:annotation-config/ and context:property-placeholder/ in respective XML file]

Spring boot versions used:
For Java based Configuration Project: v2.4.0

For XML based Configuration Project: v2.1.4

Please help

@huangyfGG
Copy link

do you now have any soluations?

@huangyfGG
Copy link

In my case,i can decryptie xml config in some linux machine, while use the same jar, in other linux machine can not decryptie xml config. the xml config is a datasource config.The log prints invalid username/password; logon denied

@Udaykumar519
Copy link
Author

Udaykumar519 commented Dec 26, 2023

@huangyfGG

I have written custom jasypt encryptor in my application, i have used this for decrypting

@configuration
public class JasyptEncryptorConfig {
@bean(name = "jasyptStringEncryptor")
public static StringEncryptor customStringEncryptor(){
PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
SimpleStringPBEConfig config = new SimpleStringPBEConfig();
config.setPassword("your_encryption_key"); // encryptor's private key
config.setAlgorithm("PBEWITHHMACSHA512ANDAES_256");
config.setKeyObtentionIterations("1000");
config.setPoolSize("1");
config.setProviderName(null);
config.setProviderClassName(null);
config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
config.setIvGeneratorClassName("org.jasypt.iv.RandomIvGenerator");
config.setStringOutputType("base64");
encryptor.setConfig(config);
return encryptor;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants