Thursday, March 10, 2016

Opening the kdbx files using the Java

In today's time people have 1000's of accounts with different types of usernames and passwords. Although I am not here to tell you how you guys manage to keep track of all those passwords in your mind but I think its a great headache for every one who want to remember the password.

So, when I tried to get the solution of this I found some of the solutions given by different companies that keeps track of all your usernames and passwords under a shelf which you can protect via a single password. The main thing here is that you just have to remember 1 password and all the other passwords are kept behind this password. Although this seems promising but I think this is a bit awkward since at any moment these companies have your very sensitive data and might be the chance that any hacker can hack in to it and get the data back the way they passes the data to us via internet.

So I gave more attention and found one more solution named Keepass that gives you the freeness to store the same for us but the main thing is that it can store the data of username and password in a file in my own computer which is a bit more secure then keeping it in any other computer. I have explained the other goodness of this in other post please go through it once and tell me your views.

So coming back to the topic the kind of file it creates is .kdbx extension. This file is fully encrypted via our password and the key file (please read other post for further info regarding the key file).

Now in order to open the key file using the java program I have done some research and found that there is a library (found here). The maven repo that is provided there is pretty updated but when I used the one that is given there ie.

<groupid>de.slackspace</groupid> <artifactid>openkeepass</artifactid> <version>0.5.0</version>
I found that this does not give the functionality to open the .kdbx file when your file is protected via a key file and a password both.

So what I did is that I have downloaded the repository from the github and then compiled it locally, which will create a local repo with the version named 0.5.1-SNAPSHOT.

This local compiled project is actually having the power to open the .kdbx file locally which is having the lock with the key file and a password. 

Here is the code snippet:
Globals.java
public class Globals {

 public static final String DB_PATH = "kdbx file path";
 public static final String KEY_PATH = "key file path";
 public static final String PASSWORD = "password";
 
}

KeepassMain.java
public class KeepassMain {
 public static void main(String[] args) throws Exception{
  KeePassFile database = KeePassDatabase.getInstance(Globals.DB_PATH).openDatabase(Globals.PASSWORD, new File(Globals.KEY_PATH));
  for(Group group : database.getGroups()){
   System.out.println(group.getName());
   for(Entry entry : group.getEntries()){
    System.out.println(entry.getTitle());
    System.out.println("\t" + entry.getUsername() + " ======== " + entry.getPassword());
    
   }
  }
 }
}


No comments:

Post a Comment