Implement a bit of Encryption
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user