subcommands and structure

- added run, save, and view subcommands
- WIP still
- moved encryption and decryption to util file
- a good start
This commit is contained in:
2025-04-16 19:25:21 -04:00
parent 8068b090ed
commit bef3521770
7 changed files with 222 additions and 20 deletions

49
cryptography/aes.go Normal file
View File

@@ -0,0 +1,49 @@
package cryptography
import (
"crypto/aes"
"crypto/cipher"
"github.com/spf13/viper"
)
func EncryptPassword(b []byte) ([]byte, error) {
nonce := viper.Get("nonce").(string)
dev := viper.Get("device").(string)
block, err := aes.NewCipher([]byte(dev))
if err != nil {
return nil, err
}
aesg, err := cipher.NewGCM(block)
if err != nil {
return nil, err
}
ct := aesg.Seal(nil, []byte(nonce), []byte(b), nil)
return ct, nil
}
func DecryptPassword(b []byte) (string, error) {
nonce := viper.Get("nonce").(string)
password := viper.Get("password").(string)
dev := viper.Get("device").(string)
block, err := aes.NewCipher([]byte(dev))
if err != nil {
return "", err
}
aesg, err := cipher.NewGCM(block)
if err != nil {
return "", err
}
op, err := aesg.Open(nil, []byte(nonce), []byte(password), nil)
if err != nil {
return "", err
}
return string(op), nil
}