func main() { file, _ := os.Open("./example.kdbx") db := gokeepasslib.NewDatabase() db.Credentials = gokeepasslib.NewPasswordCredentials("abcdefg12345678") _ = gokeepasslib.NewDecoder(file).Decode(db) db.UnlockProtectedEntries() entry := db.Content.Root.Groups[0].Groups[0].Entries[0] fmt.Println(entry.GetTitle()) fmt.Println(entry.GetPassword()) }
func loadDatabaseCmd(cmd *cobra.Command, args []string) error { var ( password string err error ) if usePassword { password, err = readPassword("Enter password: "******"Failed to setup credentials: '%s'", err) } db = new(gokeepasslib.Database) db.Credentials = credentials file, err := os.Open(filePath) if err != nil { return fmt.Errorf("Failed to open Keepass2 file %s: '%s'", filePath, err) } err = gokeepasslib.NewDecoder(file).Decode(db) if err != nil { return fmt.Errorf("Failed to decode Keepass2 file: %s", err) } if err := db.UnlockProtectedEntries(); err != nil { return err } return nil }