public void saveKdbx() throws IOException { // create an empty database D database = getDatabase(); // add some groups and entries for (Integer g = 0; g < 5; g++) { G group = database.getRootGroup().addGroup(database.newGroup(g.toString())); for (int e = 0; e <= g; e++) { // entry factory is a local helper to populate an entry group.addEntry(entryFactory(database, g.toString(), e)); } } // save to a file with password "123" try (FileOutputStream outputStream = new FileOutputStream("testOutput/test.kdbx")) { database.save(new KdbxCreds("123".getBytes()), outputStream); } }
/** * Load KDBX */ public void loadKdbx() throws IOException { // get an input stream try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test123.kdbx")) { // password credentials Credentials credentials = new KdbxCreds("123".getBytes()); // Jaxb implementation seems a lot faster than the DOM implementation D database = loadDatabase(credentials, inputStream); // visit all groups and entries and list them to console database.visit(new Visitor.Print()); } }
/** * Load KDB and save as KDBX */ public void loadKdb() throws IOException { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test123.kdb"); // password credentials Credentials credentials = new KdbCredentials.Password("123".getBytes()); // load KdbDatabase KdbDatabase database = KdbDatabase.load(credentials, inputStream); // visit all groups and entries and list them to console database.visit(new Visitor.Print()); // create a KDBX (database D kdbxDatabse = getDatabase(); kdbxDatabse.setName("New Database"); kdbxDatabse.setDescription("Migration of KDB Database to KDBX Database"); // deep copy from group (not including source group, KDB database has simulated root) kdbxDatabse.getRootGroup().copy(database.getRootGroup()); // save it try (FileOutputStream f = new FileOutputStream("testOutput/migration.kdbx")) { kdbxDatabse.save(new KdbxCreds("123".getBytes()), f); } } }