3

Whenever the question of hiding the fields like passwords in application properties file arises,the straight-forward answer is encrypt those details using jasypt or other encryption. If you keep encrypted passwords and jasypt details in same file, how does that make sense? or may be keep them in different file..

Any other smarter way for this?

ts178
  • 321
  • 1
  • 6
  • 20

3 Answers3

3

You're not supposed to save the encryption key in application.properties, after all you don't want it going to your repository. You have to provide the key to your application when you run it, either by typing it or by storing it somewhere on your server. Check this thread for examples.

prettyvoid
  • 3,446
  • 6
  • 36
  • 60
1

Let's assume that you have gotten your passwords in a typical application.properties file. Using Jaspyt, you may encrypt as follows:

  • Maven setup.... Grab the latest spring boot starter Jasypt POM, use com.github.ulisesbocchio as the group ID.
  • Create a tiny utility class (preferably outside your spring boot app) to encrypt your passwords; it's easy to use Jasypt's BasicTextEncryptor class ex:

    BasicTextEncryptor pwdEncrypt = new BasicTextEncryptor(); 
    pwdEncrypt.setPassword(your_secret_sauce)//whatever you use here will be needed in the properties file (more on that later)
    String encoded = pwdEncrypt.encrypt(password_you_want_to_encrpyt);
    
  • The String encoded is PBE-encoded by default; grab that

  • In your properties file, make the following entries:

    jasypt.encryptor.password=your_secret_sauce //used in your utility
    password_entry_you_want_to_encrypt=ENC(encoded) //encoded grabbed from your utility class
    
  • I'll assume that you're annotating your main class with @SpringBootApplication. Add the following annotations as well:

    @EnableEncryptableProperties
    @PropertySource(name="EncryptedProperties", value = "classpath:application.properties")
    
Isaac Riley
  • 290
  • 4
  • 5
0

Use jasypt to encrypt properties in application.properties file.
it's usesPBEWithMD5AndDES for the encryption.
See: https://github.com/ulisesbocchio/jasypt-spring-boot

Bacon
  • 1,229
  • 2
  • 14
  • 26
Dzshean
  • 314
  • 6
  • 23