-
Notifications
You must be signed in to change notification settings - Fork 30
/
example-deleting.go
54 lines (41 loc) · 1.12 KB
/
example-deleting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"log"
"os"
"github.com/tobischo/gokeepasslib/v3"
)
func main() {
readFilename := "example-writing.kdbx"
writeFilename := "example-deleting.kdbx"
masterPassword := "supersecret"
readFile, err := os.Open(readFilename)
if err != nil {
panic(err)
}
defer readFile.Close()
db := gokeepasslib.NewDatabase()
db.Credentials = gokeepasslib.NewPasswordCredentials(masterPassword)
err = gokeepasslib.NewDecoder(readFile).Decode(db)
if err != nil {
panic(err)
}
// Unlock protected entries to handle stream cipher
db.UnlockProtectedEntries()
rootGroup := db.Content.Root.Groups[0]
// Remove `My GMail password` entry from example-writing example
rootGroup.Entries = rootGroup.Entries[:0]
db.Content.Root.Groups[0] = rootGroup
// Lock entries using stream cipher
db.LockProtectedEntries()
writeFile, err := os.Create(writeFilename)
if err != nil {
panic(err)
}
defer writeFile.Close()
// and encode it into the file
keepassEncoder := gokeepasslib.NewEncoder(writeFile)
if err := keepassEncoder.Encode(db); err != nil {
panic(err)
}
log.Printf("Wrote kdbx file: %s", writeFilename)
}