40 lines
771 B
Go
40 lines
771 B
Go
/*
|
|
Copyright © 2024 Brian Buller <brian@bullercodeworks.com>
|
|
*/
|
|
package util
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
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)
|
|
}
|
|
func RemovePWFile(path string) error { return os.Remove(path) }
|