Skip to content

tobischo/gokeepasslib

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.1 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.1...v1.8.4)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
12ad9bc

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
June 7, 2023 18:13
April 14, 2023 07:44
September 12, 2022 16:16
January 9, 2023 18:41
November 7, 2021 17:32
November 7, 2021 17:32
August 8, 2021 09:52
November 20, 2018 22:41
September 25, 2021 20:18
August 8, 2021 09:52

gokeepasslib

GitHub Build Status GitHub go.mod Go version GitHub release (latest by date)

gokeepasslib is a library which allows reading Keepass 2 files (kdbx).

Note: only Keepass v2.30 or higher is properly supported since earlier versions do not allow empty XML tags but expected self-closing tags (which is valid XML but not really supported by Golang on XML marshaling) Basically: this lib can probably read most Keepass2 files, but only Keepass v2.30 can be expected to read files created in this lib.

Installing

Use go get to retrieve the latest version:

go get -u github.com/tobischo/gokeepasslib

Include it in an application (modulized):

import "github.com/tobischo/gokeepasslib/v3"

For non-modulized applications use:

import "github.com/tobischo/gokeepasslib"

Note that this may cause breaking changes when updating from a previous version.

Example: reading a file

package main

import (
    "fmt"
    "github.com/tobischo/gokeepasslib/v3"
    "os"
)

func main() {
    file, _ := os.Open("examples/reading/example.kdbx")

    db := gokeepasslib.NewDatabase()
    db.Credentials = gokeepasslib.NewPasswordCredentials("abcdefg12345678")
    _ = gokeepasslib.NewDecoder(file).Decode(db)

    db.UnlockProtectedEntries()

    // Note: This is a simplified example and the groups and entries will depend on the specific file.
    // bound checking for the slices is recommended to avoid panics.
    entry := db.Content.Root.Groups[0].Groups[0].Entries[0]
    fmt.Println(entry.GetTitle())
    fmt.Println(entry.GetPassword())
}

Note the db.UnlockProtectedEntries() call: you have to unlock protected entries before using the database and call db.LockProtectedEntries() before saving it to ensure that the passwords are not stored in plaintext in the xml. In kdbx files, which are encrypted using the file credentials, fields are protected with another stream cipher.

Example: writing a file

See examples/writing/example-writing.go

Example: deleting a file

See examples/deleting/example-deleting.go

TODO

  • Improve code readability
  • Write more tests

Contributing

CONTRIBUTING

Changelog

CHANGELOG

License

LICENSE

Copyright © 2023 Tobias Schoknecht. All rights reserved.