This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Read encrypted string from properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Read encrypted string from properties file" Watch "Read encrypted string from properties file" New topic

Read encrypted string from properties file

arnold yan
Ranch Hand

Joined: May 31, 2002
Posts: 40
I'm writing a password verification utility. I want to create a properties file with all users and their passwords in name/value pairs, such as
user1=password1, where password is encrypted with 3DES. I added following entry in the properties file named ""


but when I tried to retireve the encrypted password using following code,

Properties users = new Properties();
users.load(new FileInputStream("c://"));
String password = users.getProperty("tom");

The string returned is A�??��?A�U��, which is different than what is in the file and can not be decrypted.

The weird thing is, if I use the following code to pull the password,

BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream("c://")));
String line = bf.readLine();
password = line.substring(line.indexOf("=") + 1);

I got the same password as what is in the file - A������A�U��.

Can someone tell me what is going on?

D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

Yes, I can. [q]
The load and store methods load and store properties in a simple line-oriented format specified below. This format uses the ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes ; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

The loadFromXML(InputStream) and storeToXML(OutputStream, String, String) methods load and store properties in a simple XML format. By default the UTF-8 character encoding is used, however a specific encoding may be specified if required. An XML properties document has the following DOCTYPE declaration:

<!DOCTYPE properties SYSTEM "">

Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
arnold yan
Ranch Hand

Joined: May 31, 2002
Posts: 40
I'm using jdk 1.4, so loadFromXML is not available. Is there any other way that I can still use properties and get around this encoding mess?

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Read encrypted string from properties file
It's not a secret anymore!