Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read encrypted string from properties file

 
arnold yan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "users.properties"

tom=A������A�U��

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

Properties users = new Properties();
users.load(new FileInputStream("c://users.properties"));
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://users.properties")));
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?

Thanks!
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 "http://java.sun.com/dtd/properties.dtd">
[/q]
 
arnold yan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic