The attached Go script is a minimal secret management utility to securely note personal data such as usernames & passwords.
The CLI application can be started with a simple go run crypt.go
. It provides read-write interface to work with space-separated key value
lines using commands get <key-prefix>
, set <key> <value>
, del <key>
, show
, list
, save
, quit
.
The application requires a central key on startup, & loads any previously saved data. The plain text & central key stay in process memory, and only AES-256 encrypted cipher text is written to storage. The cipher text can be replicated across devices or uploaded to personal cloud drive.
The script can also be tweaked slightly to capture encrypted timed logs instead of key-value pairs,
package main
import (
"bufio"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"fmt"
"io"
"os"
"strings"
"time"
)
func main() {
.
.
.
fmt.Print("\033[1;34mUser : \033[0m")
var user string
fmt.Scan(&user)
fmt.Println()
rd := bufio.NewReader(os.Stdin)
for {
fmt.Print("\033[1;34m> \033[0m")
var command string
command, err := rd.ReadString('\n')
if err != nil { panic(err) }
switch strings.Fields(command)[0] {
case ":r":
fmt.Println(plainText)
case ":w":
cipherText, err := EncryptMessage(key, plainText)
if err != nil { panic(err) }
err = os.WriteFile(file, cipherText, 0644)
if err != nil { panic(err) }
fmt.Println()
case ":q":
fmt.Println()
return
default:
plainText += "\n\033[1;35m[" + time.Now().Format("06-01-02_03:04:05PM") + "] " + user + " >\033[0m " + command;
fmt.Println()
}
}
}
.
.
.