diff --git a/.gitignore b/.gitignore index 6411b36..5e424e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ /main.exe /rcw /rcw.exe +/ex-cipher.rcw +/ex-sanity.rcw diff --git a/example.go b/example.go index 54b90b6..6f392c5 100644 --- a/example.go +++ b/example.go @@ -11,6 +11,7 @@ import ( // of RCW before building it into your own application. // // Usage: +// rcw init : Generates the required sanity check file // rcw : 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 : Encrypts the provided text and outputs the ciphertext to encrypted-example.txt @@ -35,8 +36,17 @@ func main() { // serve data daemon.Start(os.Args[1]) case 3: + if os.Args[1] == "init" { + // create sanity check file + err := wrappers.GenSanityCheck("ex-sanity.rcw", []byte(os.Args[2])) + if err != nil { + fmt.Println(err) + } + return + } + // decrypt file - encBytes, _ := os.ReadFile("encrypted-example.txt") + encBytes, _ := os.ReadFile("ex-cipher.rcw") decBytes, err := wrappers.Decrypt(encBytes, []byte(os.Args[2])) if err != nil { fmt.Println(err) @@ -45,8 +55,13 @@ func main() { fmt.Println(string(decBytes)) case 4: // encrypt data (from cli args) + err := wrappers.RunSanityCheck("ex-sanity.rcw", []byte(os.Args[3])) + if err != nil { + fmt.Println(err) + return + } encBytes := wrappers.Encrypt([]byte(os.Args[2]), []byte(os.Args[3])) - os.WriteFile("encrypted-example.txt", encBytes, 0644) + os.WriteFile("ex-cipher.rcw", encBytes, 0600) default: // request served data fmt.Println(daemon.Call()) diff --git a/wrappers/sanityCheck.go b/wrappers/sanityCheck.go index 82eadb5..6e16c3f 100644 --- a/wrappers/sanityCheck.go +++ b/wrappers/sanityCheck.go @@ -8,8 +8,9 @@ import ( // GenSanityCheck creates an encrypted file containing known plaintext // to later be used for ensuring the user does not encrypt data with // an incorrect passphrase. -func GenSanityCheck(path string, passphrase []byte) { - os.WriteFile(path, Encrypt([]byte("thx4usin'rcw"), passphrase), 0600) +func GenSanityCheck(path string, passphrase []byte) error { + err := os.WriteFile(path, Encrypt([]byte("thx4usin'rcw"), passphrase), 0600) + return err } // RunSanityCheck should be run before any encryption operation