Initial encryption/decryption via ChaCha20-Poly1305

This commit is contained in:
2025-05-03 17:13:09 -04:00
parent 9b106e8147
commit 84bd8c3a42
5 changed files with 117 additions and 2 deletions
+24 -2
View File
@@ -4,12 +4,34 @@ import (
"fmt"
"os"
"rcw/daemon"
"rcw/wrappers"
)
// This sample program serves purley as a way to interactively test the features
// of RCW before building it into your own application.
//
// Usage:
// rcw <text> : Runs the rcw daemon to serve the provided text for three minutes
// rcw : Requests the data served by the RCW daemon and outputs it to stdout
// rcw enc <text> <passwd> : Encrypts the provided text and outputs the ciphertext to encrypted-example.txt
// rcw dec <passwd> : Decrypts the provided file and outputs the plaintext to stdout
func main() {
if len(os.Args) > 1 {
switch len(os.Args) {
case 2:
// serve data
daemon.Start(os.Args[1])
} else {
case 3:
// decrypt file
encBytes, _ := os.ReadFile("encrypted-example.txt")
decBytes := wrappers.DecryptCha(encBytes, []byte(os.Args[2]))
fmt.Println(string(decBytes))
case 4:
// encrypt data (from cli args)
encBytes := wrappers.EncryptCha([]byte(os.Args[2]), []byte(os.Args[3]))
os.WriteFile("encrypted-example.txt", encBytes, 0644)
default:
// request served data
fmt.Println(daemon.Call())
}
}