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 8661197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:26:29+00:00 2026-06-12T16:26:29+00:00

I want to keep encoded password in my below mentioned springApplicationContext.xml Is there any

  • 0

I want to keep encoded password in my below mentioned springApplicationContext.xml

Is there any way to achieve this?

presently I have configured all properties using property-placeholder
as shown below but the raw password is still open in my database.properties

springApplicationContext.xml

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <beans:property name="driverClassName"><beans:value>${db.driverClassName}</beans:value></beans:property>
        <beans:property name="url"><beans:value>${db.url}</beans:value></beans:property>
        <beans:property name="username"><beans:value>${db.username}</beans:value></beans:property>
        <beans:property name="password"><beans:value>${db.password}</beans:value></beans:property>
</beans:bean>

but actual values are present in my database.properties

db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost/myDB
db.username=root
db.password=root

I want something like below:

springApplicationContext.xml (same as above)

<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <beans:property name="driverClassName"><beans:value>${db.driverClassName}</beans:value></beans:property>
        <beans:property name="url"><beans:value>${db.url}</beans:value></beans:property>
        <beans:property name="username"><beans:value>${db.username}</beans:value></beans:property>
        <beans:property name="password"><beans:value>${db.password}</beans:value></beans:property>
</beans:bean>

But password property value should be in encripted format in my database.properties

db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost/myDB
db.username=root
db.password=3g6n72ef8x (using any encription method).

and my dataSource internally decrypt the password before making new DB connection.

Highly appreciate for any help/suggestion in this.

  • 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-12T16:26:30+00:00Added an answer on June 12, 2026 at 4:26 pm

    Its might be funny that I am answering to my own question. but still I just wanted to tell my solution, others who might have faced same kind of issue..

    for simplicity I have used BASE64Encoder & BASE64Decoder. later I will modify my code to use a secure/better encryption/decryption algorithm.

    I have encoded my database password(ex: root for my case) by using the below code:

    private String encode(String str) {
            BASE64Encoder encoder = new BASE64Encoder();
            str = new String(encoder.encodeBuffer(str.getBytes()));
            return str;
        }
    

    and placed the encoded password in my database.properties file like below:

    before

    db.driverClassName=com.mysql.jdbc.Driver
    db.url=jdbc:mysql://localhost/myDB
    db.username=root
    db.password=root
    

    after

    db.driverClassName=com.mysql.jdbc.Driver
    db.url=jdbc:mysql://localhost/myDB
    db.username=root
    db.password=cm9vdA==  (Note: encoded 'root' by using BASE64Encoder)
    

    Now I have written a wrapper class for org.apache.commons.dbcp.BasicDataSource
    and overridden setPassword() method:

    import java.io.IOException;
    import org.apache.commons.dbcp.BasicDataSource;
    import sun.misc.BASE64Decoder;
    
    public class MyCustomBasicDataSource extends BasicDataSource{
    
        public CustomBasicDataSource() {
            super();
        }
    
        public synchronized void setPassword(String encodedPassword){
            this.password = decode(encodedPassword);
        }
    
        private String decode(String password) {
            BASE64Decoder decoder = new BASE64Decoder();
            String decodedPassword = null;
            try {
                decodedPassword = new String(decoder.decodeBuffer(password));
            } catch (IOException e) {
                e.printStackTrace();
            }       
            return decodedPassword;
        }
    }
    

    This way I am decoding(BASE64Decoder) the encoded password provided in database.properties

    and also modified the class attribute of my dataSource bean mentioned in springApplicationContext.xml file.

    <beans:bean id="dataSource" class="edu.config.db.datasource.custom.MyCustomBasicDataSource" destroy-method="close">
        <beans:property name="driverClassName"><beans:value>${db.driverClassName}</beans:value></beans:property>
        <beans:property name="url"><beans:value>${db.url}</beans:value></beans:property>
        <beans:property name="username"><beans:value>${db.username}</beans:value></beans:property>
        <beans:property name="password"><beans:value>${db.password}</beans:value></beans:property>
    

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website where I want keep track of the Statistics about the
The following string gets encoded in my source XML using toggles, and I want
I want to have a trail that helps keep track of values I want
I want to keep my footer at the bottom of the page while keeping
i want to keep my app in sync with the Server. The communication between
I want to keep an element always visible, even when it should be scrolled
I want to keep my list GWT side after fetch it from service side.For
I want to keep tabs on the number of concurrent users of my application.
I want to keep a cell selected, and only change when I select another
I want to keep SSH debug info separate (and logged) from other input. However,

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.