public static void testDb (DbLoader loader, String label, int loads, int iterations) throws Exception { KdbxCreds creds = new KdbxCreds("123".getBytes()); long start = System.currentTimeMillis(); for (int i=0; i < loads; i++) { try (InputStream inputStream = OpenDbExample.class.getClassLoader().getResourceAsStream("test1.kdbx")) { Database database = loader.load(creds, inputStream); for (int j = 0; j < iterations; j++) { database.visit(new Visitor.Default() { }); } } } System.out.printf("%s %d loads %d iterations %d millis%n", label, loads, iterations, System.currentTimeMillis()-start); }
/** * 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()); } }
public static void main(String[] args) throws Exception { Server server = new Server(); ServerConnector http = new ServerConnector(server); http.setHost("127.0.0.1"); http.setPort(19455); http.setIdleTimeout(300000); server.addConnector(http); KdbxCreds creds = new KdbxCreds("123".getBytes()); // create a database if we don't have one already if (Files.notExists(Paths.get(DEFAULT_DB_FILE))) { SimpleDatabase db = new SimpleDatabase(); db.setName("HTTP Database"); db.save(creds,new FileOutputStream(DEFAULT_DB_FILE)); } DatabaseAdaptor adaptor = new DatabaseAdaptor.Default(new File(DEFAULT_DB_FILE), creds, new HexPwGenerator(10)); server.setHandler(new KeePassHttpHandler(adaptor)); server.start(); server.join(); } }
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); } }
Credentials credentials = new KdbxCreds("123".getBytes()); org.linguafranca.pwdb.kdbx.stream_3_1.KdbxHeader kdbxHeader = new org.linguafranca.pwdb.kdbx.stream_3_1.KdbxHeader(); try (InputStream decryptedInputStream = KdbxSerializer.createUnencryptedInputStream(credentials, kdbxHeader, encryptedInputStream)) {
/** * 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); } } }