Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hudeany/kdbx.git into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas authored and Andreas committed Jul 9, 2023
2 parents f7902e8 + f4be288 commit 8e724e2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,31 @@ try (KdbxReader kdbxReader = new KdbxReader(new FileInputStream("MyKeePassDataba
### KdbxWriter example with simple password:
```java
KdbxDatabase database = new KdbxDatabase();
database.getMeta().setDatabaseName("MyDatabase");

final KdbxEntry kdbxEntry = new KdbxEntry();
kdbxEntry.setTitle("MyEntry");
kdbxEntry.setUrl("https://MyDomain");
kdbxEntry.setUsername("MyUsernameForThisEntry");
kdbxEntry.setPassword("MyPasswordForThisEntry");
database.getEntries().add(kdbxEntry);

try (KdbxWriter kdbxWriter = new KdbxWriter(new FileOutputStream("MyKeePassDatabase.kdbx"))) {
kdbxWriter.writeKdbxDatabase(database, "MyDatabasePassword".toCharArray());
kdbxWriter.writeKdbxDatabase(database, "MyDatabasePassword".toCharArray());
} catch (final Exception e) {
e.printStackTrace();
e.printStackTrace();
}

try (KdbxReader kdbxReader = new KdbxReader(new FileInputStream("MyKeePassDatabase.kdbx")).setStrictMode(true)) {
database = kdbxReader.readKdbxDatabase("MyDatabasePassword".toCharArray());
System.out.println(database.getHeaderFormat().getDataFormatVersion().toString());
System.out.println(database.getMeta().getDatabaseName());
System.out.println(database.getAllEntries().size());
System.out.println(database.getEntries().get(0).getTitle());
System.out.println(database.getEntries().get(0).getUrl());
System.out.println(database.getEntries().get(0).getUsername());
System.out.println(database.getEntries().get(0).getPassword());
} catch (final Exception e) {
e.printStackTrace();
}
```

0 comments on commit 8e724e2

Please sign in to comment.