[][src]Crate kdbx_rs

Module to read and write KDBX (Keepass 2) databases.

The main types in this crate are:

  • Database which represents a password database
  • Kdbx which represents a database archive, including encryption options

Opening a database

Databases can be read with the kdbx_rs::open function. This provides access to header information. It can then be unlocked by providing a CompositeKey to the Kdbx.unlock method to access any encrypted data.

use kdbx_rs::CompositeKey;

let kdbx = kdbx_rs::open(file_path)?;
let key = CompositeKey::from_password("kdbxrs");
let unlocked = kdbx.unlock(&key)?;

Alternatively, kdbx_rs::from_reader can be used to open a database from a non file source (such as in-memory or a network stream)

Generating a new password database

A database can be created in memory by using the Database::default() method. This will create an empty database which you can then populate.

use kdbx_rs::database::{Database, Entry};

let mut database = Database::default();
database.set_name("My First Database");
database.set_description("Created with kdbx-rs");

let mut entry = Entry::default();


Saving a database to a file

To save a database to a file, you first need to create a Kdbx instance from that database, for example with Kdbx::from_database. This will generate encryption options using salts and random values from the OS's secure RNG. These can be customised, or you can save the database as is.

Before saving a new database for the first time, you'll need to set the user credentials to save your database. This can be done with Kdbx.set_key. Provide a CompositeKey instance, which can be created the same way as for unlocking database. This will then be used to generate the remaining keys allowing you to save the database using [Kdbx.write()]

use kdbx_rs::{CompositeKey, Kdbx};

let mut kdbx = Kdbx::from_database(database);

let mut file = File::create(file_path).unwrap();
kdbx.write(&mut file)?;

Database operations

See the database module-level documentation for examples of database operations.


pub use crate::database::Database;
pub use errors::Error;



.kdbx archives and the outer binary format


Keepass data types


Error types for kdbx-rs


Utilities to help working with kdbx-rs


Work directly with the KDBX decrypted inner XML format



Credentials needed to unlock the database


A KeePass 2 archive wrapping a password database



Read a database from a input stream


Read a database from a given path