• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read encrypted string from properties file

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 472
Objective C Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic