Code Monkey home page Code Monkey logo

gokeepasslib's Introduction

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

Copyright © 2023 Tobias Schoknecht. All rights reserved.

gokeepasslib's People

Contributors

tobischo avatar kev-the-dev avatar alessiodp avatar korovan-software avatar joonas-fi avatar dependabot[bot] avatar rspier avatar npotts avatar kgadams avatar mjholub avatar martinseener avatar ariarijp avatar shizeeg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.