Implement a bit of Encryption

This commit is contained in:
2024-05-15 15:10:38 -05:00
parent c253ca6fdf
commit 65d8a457a3
3 changed files with 38 additions and 10 deletions

View File

@@ -3,7 +3,9 @@ Copyright © 2024 Brian Buller <brian@bullercodeworks.com>
*/
package util
import "io/ioutil"
import (
"io/ioutil"
)
func ReadFile(path string) (string, error) {
var bytesRead []byte
@@ -14,6 +16,22 @@ func ReadFile(path string) (string, error) {
return string(bytesRead), nil
}
func WritePWFile(path, contents string) error {
return ioutil.WriteFile(path, []byte(contents), 0600)
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)
}