Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:09:54+00:00 2026-06-03T00:09:54+00:00

I have a java application that connects to a database. The user name and

  • 0

I have a java application that connects to a database.
The user name and password for the database are stored in a properties file.
What is the common practice to avoid storing the password in cleartext in the properties file while still retaining the option to let the user change it?
The main motivation here is to prevent someone looking over the admin’s shoulder and seeing the password while the admin is editing the properties file.
I read here that there’s a built in way to do it in C#.
Knowing java, I don’t expect to find a built in solution but I’d like to hear what other people are doing.
If I don’t find any good choice then I am probably going to encrypt it with a constant password that will be kept in the code. But I’d hate to do it this way because it feels wrong.

Edit Dec 12th 2012
Looks like there is no magic and I must store the password in the code or something similar.
At the end we implemented something very similar to what Jasypt that was mentioned in one of the answers does.
So I’m accepting the Jasypt answer because it is the closest thing to a definite answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:09:55+00:00Added an answer on June 3, 2026 at 12:09 am

    enter image description here

    Jasypt provides the org.jasypt.properties.EncryptableProperties class for loading, managing and transparently decrypting encrypted values in .properties files, allowing the mix of both encrypted and not-encrypted values in the same file.

    http://www.jasypt.org/encrypting-configuration.html

    By using an org.jasypt.properties.EncryptableProperties object, an
    application would be able to correctly read and use a .properties file
    like this:

    datasource.driver=com.mysql.jdbc.Driver 
    datasource.url=jdbc:mysql://localhost/reportsdb 
    datasource.username=reportsUser 
    datasource.password=ENC(G6N718UuyPE5bHyWKyuLQSm02auQPUtm) 
    

    Note that
    the database password is encrypted (in fact, any other property could
    also be encrypted, be it related with database configuration or not).

    How do we read this value? like this:

    /*
    * First, create (or ask some other component for) the adequate encryptor for   
    * decrypting the values in our .properties file.   
    */  
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();     
    encryptor.setPassword("jasypt"); // could be got from web, env variable...    
    /*   
    * Create our EncryptableProperties object and load it the usual way.   
    */  
    Properties props = new EncryptableProperties(encryptor);  
    props.load(new FileInputStream("/path/to/my/configuration.properties"));
    
    /*   
    * To get a non-encrypted value, we just get it with getProperty...   
    */  
    String datasourceUsername = props.getProperty("datasource.username");
    
    /*   
    * ...and to get an encrypted value, we do exactly the same. Decryption will   
    * be transparently performed behind the scenes.   
    */ 
    String datasourcePassword = props.getProperty("datasource.password");
    
     // From now on, datasourcePassword equals "reports_passwd"...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a Java Application that connects with a database (insert, select ...)
I have a java application that connects to a Sybase database. I want to
I have an Java application that connects to database. In the production environment, the
I have a Java application that makes heavy use of a large file, to
i have an Java J2ME application that does (at user request) create HttpConnections to
I have made a java application that stores data from a .csv file to
I have created a java SE application that uses the mysql database using mysql
i have to write small java database application with several tables. With that i
I am creating a java application that connects to multiple databases. A user will
I am writing a Java JDBC database application that connects to an Oracle 11g

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.