public class KdbxSerializer extends Object
KDBX files are little-endian and consist of the following:
The header fields are encoded using a TLV style. The Type is an enumeration encoded in 1 byte.
The length is encoded in 4 bytes (V3: 2 bytes) and the value according to the length denoted. The sequence is
terminated by a zero type with 0 length. readOuterHeader(java.io.InputStream, org.linguafranca.pwdb.kdbx.KdbxHeader)
In V4 there follows a 32 byte SHA-256 hash of the file so far
In V4 there follows a 32 byte HMAC-256 hash of the file so far
KdbxHeader details the fields of the header.
HashedBlockInputStream for details of this.HmacBlockInputStreamreadInnerHeader(org.linguafranca.pwdb.kdbx.KdbxHeader, java.io.InputStream)
followed by XML representing a KeePass Database. Assumed UTF-8 encoding.The methods in this class provide support for serializing and deserializing plain text payload content to and from the above encrypted format.
Various fields of the plain text XML (e.g. passwords) are additionally and optionally encrypted using a second encryption. They are stream encrypted, meaning they have to be decrypted in the same order as they were encrypted, namely actual XML document order. Or at least that is the way it seems. The methods of this class do not perform this aspect of encryption/decryption.
| Modifier and Type | Method and Description |
|---|---|
static OutputStream |
createEncryptedOutputStream(Credentials credentials,
KdbxHeader kdbxHeader,
OutputStream outputStream)
Provides an
OutputStream to be encoded and encrypted in KDBX format |
static InputStream |
createUnencryptedInputStream(Credentials credentials,
KdbxHeader kdbxHeader,
InputStream inputStream)
Provides the payload of a KDBX file as an unencrypted
InputStream. |
static KdbxHeader |
readOuterHeader(InputStream inputStream,
KdbxHeader kdbxHeader)
Create and populate a KdbxHeader from the input stream supplied
|
static void |
readOuterHeaderVerification(KdbxHeader kdbxHeader,
Credentials credentials,
DataInput input)
V4 header is followed by an SHA256 and then contains an HMAC SHA256 after that.
|
static VariantDictionary |
readVariantDictionary(byte[] source)
Read a VariantDictionary from the supplied input according to KDBX rules
|
static byte[] |
serializeVariantDictionary(VariantDictionary v)
Serialize a variant dictionary according to KDBX rules
|
static void |
writeInnerHeader(KdbxHeader kdbxHeader,
OutputStream outputStream) |
static void |
writeKdbxHeader(KdbxHeader kdbxHeader,
OutputStream outputStream)
Write a KdbxHeader to the output stream supplied.
|
public static InputStream createUnencryptedInputStream(Credentials credentials, KdbxHeader kdbxHeader, InputStream inputStream) throws IOException
InputStream.credentials - credentials for decryption of the streamkdbxHeader - a KdbxHeader for the encryption parameters and so oninputStream - a KDBX formatted input streamIOException - on errorpublic static OutputStream createEncryptedOutputStream(Credentials credentials, KdbxHeader kdbxHeader, OutputStream outputStream) throws IOException
OutputStream to be encoded and encrypted in KDBX formatcredentials - credentials for encryption of the streamkdbxHeader - a KDBX header to control the formatting and encryption operationoutputStream - output stream to contain the KDBX formatted outputIOException - on errorpublic static KdbxHeader readOuterHeader(InputStream inputStream, KdbxHeader kdbxHeader) throws IOException
inputStream - an input streamIOException - on errorpublic static void readOuterHeaderVerification(KdbxHeader kdbxHeader, Credentials credentials, DataInput input) throws IOException
kdbxHeader - the header containing the relevant parameterscredentials - the credentials - used to verify the HMACinput - an input sourceIOException - on errorpublic static void writeKdbxHeader(KdbxHeader kdbxHeader, OutputStream outputStream) throws IOException
kdbxHeader - the header to write and updateIOException - on errorpublic static void writeInnerHeader(KdbxHeader kdbxHeader, OutputStream outputStream) throws IOException
IOExceptionpublic static VariantDictionary readVariantDictionary(byte[] source)
source - source of datapublic static byte[] serializeVariantDictionary(VariantDictionary v)
v - the dictionary to serializeCopyright © 2025. All rights reserved.