keepass-cli/util/files.go

40 lines
771 B
Go
Raw Normal View History

2024-05-15 18:49:50 +00:00
/*
Copyright © 2024 Brian Buller <brian@bullercodeworks.com>
*/
2024-05-15 18:42:38 +00:00
package util
2024-05-15 20:10:38 +00:00
import (
"io/ioutil"
2024-05-17 12:50:03 +00:00
"os"
2024-05-15 20:10:38 +00:00
)
2024-05-15 18:42:38 +00:00
func ReadFile(path string) (string, error) {
var bytesRead []byte
var err error
if bytesRead, err = ioutil.ReadFile(path); err != nil {
return "", err
}
return string(bytesRead), nil
}
2024-05-15 20:10:38 +00:00
func ReadPWFile(path string) (string, error) {
encPass, err := ReadFile(path)
if err != nil {
return "", err
}
var pass string
pass, err = Decrypt(GenTodayKey(), encPass)
if err != nil {
return "", err
}
return pass, nil
}
func WritePWFile(path, pw string) error {
pass, err := Encrypt(GenTodayKey(), pw)
if err != nil {
return err
}
return ioutil.WriteFile(path, []byte(pass), 0600)
2024-05-15 18:42:38 +00:00
}
2024-05-17 12:50:03 +00:00
func RemovePWFile(path string) error { return os.Remove(path) }