Code Monkey home page Code Monkey logo

Comments (6)

ulisesbocchio avatar ulisesbocchio commented on May 22, 2024 1

checkout the demo app https://github.com/ulisesbocchio/jasypt-spring-boot/tree/master/jasypt-spring-boot-demo-custom-encryptor

That works just fine. That one renames the actual bean name in application.yml, but you can just remove the renaming in application.yml and rename the static bean as jasyptStringEncryptor and it works just fine.
Please make sure you declare your bean static:

    @Bean(name="jasyptStringEncryptor")
    static public StringEncryptor stringEncryptor() {
        PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
        SimpleStringPBEConfig config = new SimpleStringPBEConfig();
        config.setPassword("password");
        config.setAlgorithm("PBEWithMD5AndDES");
        config.setKeyObtentionIterations("1000");
        config.setPoolSize("1");
        config.setProviderName("SunJCE");
        config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
        config.setStringOutputType("base64");
        encryptor.setConfig(config);
        return encryptor;
    }

from jasypt-spring-boot.

ulisesbocchio avatar ulisesbocchio commented on May 22, 2024

Are you experiencing any error? I'm not sure what you're asking. The bean rename is to overcome a limitation of Spring that doesn't allow ${pace.holders} in bean names. Since I want users to be able to define their own bean name if they want.

from jasypt-spring-boot.

6Niner avatar 6Niner commented on May 22, 2024

Hi Ulises,
Let me try to describe the scenario a little better this time. I went
through your brief documentation on GitHub and inferred that if I write a
decryption method that returns an object of type StringEncryptor with a
@bean(name="jasyptStringEncryptor") preceeding it, the default
StringEncryptor will not be initialized by jasypt-spring-boot. So I did the
same but upon running the application, I saw that my custom encryptor was
being overriden by jasypt's default string encryptor having the same bean
name. As per my understanding the default is overridden by the custom and
not the other way round. Inspite of me writing the custom method and
providing certain value to fields such as the randomsaltgenerator and
keyobtentioniterations, it always picked up the default values and in the
logs i could see that:

  1. It overrides the custom bean with the default one
  2. As a result it uses the default property values.

Hope this explains the scenario better.

I would also like to mention that I really appreciate the work you are
doing to make life easier for developers around the globe.

Thanks & Regards,
Debanjan.
On Apr 21, 2016 4:49 AM, "Ulises Bocchio" [email protected] wrote:

Are you experiencing any error? I'm not sure what you're asking. The bean
rename is to overcome a limitation of Spring that doesn't allow
${pace.holders} in bean names. Since I want users to be able to define
their own bean name if they want.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#23 (comment)

from jasypt-spring-boot.

6Niner avatar 6Niner commented on May 22, 2024

Hi Ulises,
I am not using yml currently but I will surely give it a try. Thanks for
your time and your prompt reply.

Thanks & Regards,
Debanjan.
On Apr 21, 2016 5:19 AM, "Ulises Bocchio" [email protected] wrote:

checkout the demo app
https://github.com/ulisesbocchio/jasypt-spring-boot/tree/master/jasypt-spring-boot-demo-custom-encryptor

That works just fine. That one renames the actual bean name in
application.yml, but you can just remove the renaming in application.yml
and rename the static bean as jasyptStringEncryptor and it works just
fine.
Please make sure you declare your bean static:

@Bean(name="jasyptStringEncryptor")
static public StringEncryptor stringEncryptor() {
    PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
    SimpleStringPBEConfig config = new SimpleStringPBEConfig();
    config.setPassword("password");
    config.setAlgorithm("PBEWithMD5AndDES");
    config.setKeyObtentionIterations("1000");
    config.setPoolSize("1");
    config.setProviderName("SunJCE");
    config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
    config.setStringOutputType("base64");
    encryptor.setConfig(config);
    return encryptor;
}


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#23 (comment)

from jasypt-spring-boot.

ulisesbocchio avatar ulisesbocchio commented on May 22, 2024

no problem buddy, it doesn't matter whether you use yaml or not. Just make your custom encryptor bean static and that should fix it.
I'm closing this, please reopen should you haven further issues
Best,
Uli

from jasypt-spring-boot.

akashshinde44comp avatar akashshinde44comp commented on May 22, 2024

I am getting below error -

Caused by: com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed, make sure encryption/decryption passwords match
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.resolvePropertyValue(DefaultPropertyResolver.java:37) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver.resolvePropertyValue(DefaultLazyPropertyResolver.java:41) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource.getProperty(EncryptablePropertySource.java:16) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.wrapper.EncryptableMapPropertySourceWrapper.getProperty(EncryptableMapPropertySourceWrapper.java:29) ~[jasypt-spring-boot-1.16.jar:na]
at org.springframework.boot.bind.PropertySourcesPropertyValues.getEnumerableProperty(PropertySourcesPropertyValues.java:153) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.processEnumerablePropertySource(PropertySourcesPropertyValues.java:136) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.processPropertySource(PropertySourcesPropertyValues.java:115) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertySourcesPropertyValues.(PropertySourcesPropertyValues.java:105) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertiesConfigurationFactory.getPropertySourcesPropertyValues(PropertiesConfigurationFactory.java:336) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertiesConfigurationFactory.getPropertyValues(PropertiesConfigurationFactory.java:329) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:284) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:256) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:347) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
... 110 common frames omitted
Caused by: org.jasypt.exceptions.EncryptionOperationNotPossibleException: null
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:981) ~[jasypt-1.8.jar:na]
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:717) ~[jasypt-1.8.jar:na]
at org.jasypt.encryption.pbe.PooledPBEStringEncryptor.decrypt(PooledPBEStringEncryptor.java:500) ~[jasypt-1.8.jar:na]
at com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor.decrypt(DefaultLazyEncryptor.java:81) ~[jasypt-spring-boot-1.16.jar:na]
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.resolvePropertyValue(DefaultPropertyResolver.java:35) ~[jasypt-spring-boot-1.16.jar:na]
... 122 common frames omitted

from jasypt-spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.