Skip to content

Commit

Permalink
update readme with improved usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcb committed Oct 14, 2020
1 parent 663bfd4 commit 27f638a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 45 deletions.
45 changes: 15 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,29 @@ Bob opens a terminal and runs:

It prints out the following message:

run this command to encrypt data: ./build/linux/amd64/secretshare AAAAB3NzaC1yc2EAAAADAQABAAABAQCwuaFN5PT7fd67c/FdPtjxmzN4ZpoT3nq832zpizoOJAJBSTRTIUltjeh2PTAlml9nKodPODvZxTw88w695vdoB7mpLUfCKXKKtI/9DV8Ay7NJKoiQK9hwofgaPXBfSMfp5veMEw8iD3OKqkFdBbYryxwUhhGICktUuUaQHpQVVuHNjlbRoVBxnb8mp4apP2B627ARBCqyRXz00pY2u9zk96GLbpaNvE7ON50G0BG4qb9iy+09hWtMC8unncSw4AT+/Oihwe1/sVdvQunWj/27rnPHbrzCplkUO+59HXYhE/LUypbzSGGVyAOsBVeWcdg3v1oXmb9LaaXh8HDb2Od7
To decrypt data, run: ./build/linux/amd64/secretshare decrypt < file_to_decrypt
To encrypt data, run: ./build/linux/amd64/secretshare <encryption_key> < data_to_encrypt

For example if someone wanted to send you data, they would run:
./build/linux/amd64/secretshare AAAAB3NzaC1yc2EAAAADAQABAAABAQCkSAXQqyy+99uJGaYy6dBVNITdTrYeNewigGhx6/SrPppJX7KLPo6qSI8vP/ej8VDiFJGB4FjbiCLarkn1X1e1F4GW7CkjylUmD1X7njl6EeuZSzqvzsWoyO3Pgwa94d/mkQNvfvGyC9FopJh0pdVbLcPuyX75Tc6SmD8jq9PifoyC3nX2qeUOSZMgjbADpsIGABENaaDs1gTeRp2KwYHG2UwxnAUNKoANFIUK1McAL37xSJJ32pY4vEtlYxzhu2Rji7fUvQB4gqWhKuoOOoP1aP4zcOSPORMyZyPOPLT3SiVnW4GI10j0p73Y/aoYeg0eRUvhKB8WDRwOXIldgWrv

Then waits for bob to enter an encypted message via the prompt:
Bob replies to Alice and tells her she can send him data using:

enter encrypted data
./build/linux/amd64/secretshare AAAAB3NzaC1yc2EAAAADAQABAAABAQCkSAXQqyy+99uJGaYy6dBVNITdTrYeNewigGhx6/SrPppJX7KLPo6qSI8vP/ej8VDiFJGB4FjbiCLarkn1X1e1F4GW7CkjylUmD1X7njl6EeuZSzqvzsWoyO3Pgwa94d/mkQNvfvGyC9FopJh0pdVbLcPuyX75Tc6SmD8jq9PifoyC3nX2qeUOSZMgjbADpsIGABENaaDs1gTeRp2KwYHG2UwxnAUNKoANFIUK1McAL37xSJJ32pY4vEtlYxzhu2Rji7fUvQB4gqWhKuoOOoP1aP4zcOSPORMyZyPOPLT3SiVnW4GI10j0p73Y/aoYeg0eRUvhKB8WDRwOXIldgWrv

Bob carefully leaves his terminal running (if he were to quit it, he would no longer be able to decode the data).
Bob sends the message to alice over slack:
Alice then runs the command:

Hey Alice, you can send me a secret using secretshare by running it like:
./build/linux/amd64/secretshare AAAAB3NzaC1yc2EAAAADAQABAAABAQCwuaFN5PT7fd67c/FdPtjxmzN4ZpoT3nq832zpizoOJAJBSTRTIUltjeh2PTAlml9nKodPODvZxTw88w695vdoB7mpLUfCKXKKtI/9DV8Ay7NJKoiQK9hwofgaPXBfSMfp5veMEw8iD3OKqkFdBbYryxwUhhGICktUuUaQHpQVVuHNjlbRoVBxnb8mp4apP2B627ARBCqyRXz00pY2u9zk96GLbpaNvE7ON50G0BG4qb9iy+09hWtMC8unncSw4AT+/Oihwe1/sVdvQunWj/27rnPHbrzCplkUO+59HXYhE/LUypbzSGGVyAOsBVeWcdg3v1oXmb9LaaXh8HDb2Od7
echo "Here's your new password. Dont share it with anyone. I hope nobody decrypts this message. anyway it's "querty". Have fun." | ./build/linux/amd64/secretshare AAAAB3NzaC1yc2EAAAADAQABAAABAQCkSAXQqyy+99uJGaYy6dBVNITdTrYeNewigGhx6/SrPppJX7KLPo6qSI8vP/ej8VDiFJGB4FjbiCLarkn1X1e1F4GW7CkjylUmD1X7njl6EeuZSzqvzsWoyO3Pgwa94d/mkQNvfvGyC9FopJh0pdVbLcPuyX75Tc6SmD8jq9PifoyC3nX2qeUOSZMgjbADpsIGABENaaDs1gTeRp2KwYHG2UwxnAUNKoANFIUK1McAL37xSJJ32pY4vEtlYxzhu2Rji7fUvQB4gqWhKuoOOoP1aP4zcOSPORMyZyPOPLT3SiVnW4GI10j0p73Y/aoYeg0eRUvhKB8WDRwOXIldgWrv

Which outputs:

Alice then Runs the above command and sees:
DpNw53fz1c2TUVwXTO/K2w5CYPvARTVzjzQb/9Rdt8+lW7tfFy8t9BWqdwN2vq7lwMjkqmKxJIKDhc8OwMh+TkMrmC4Q0Qr146td9E9vu+XV5LyBD7OlYXqFo0edE9QmyrRCcG9teV3XuLpmO7XgnenYnyOTySepjHX1rZgff6VVGn1dWtHLKk32H6D39q+HkY+8k+cTUgXwWe3rJTcjipXJAsDmH9/DoPJcCwH/Rc/9mz+zJW9YEiASuxl37e639erSFY3JwTTTOfnBzOoS4pWJPQtpCNdx77RXlSbNPyx+CgBMLpx5/QgqyLcBe0mWf2pA17eYHN3Z6gDt3Wsavg==

enter data to encrypt
She sends this encrypted data to Bob, who runs the following command to decrypt it:

She enters the following data:

Here's your new password. Dont share it with anyone. I hope nobody decrypts this message. anyway it's "querty". Have fun.
echo "DpNw53fz1c2TUVwXTO/K2w5CYPvARTVzjzQb/9Rdt8+lW7tfFy8t9BWqdwN2vq7lwMjkqmKxJIKDhc8OwMh+TkMrmC4Q0Qr146td9E9vu+XV5LyBD7OlYXqFo0edE9QmyrRCcG9teV3XuLpmO7XgnenYnyOTySepjHX1rZgff6VVGn1dWtHLKk32H6D39q+HkY+8k+cTUgXwWe3rJTcjipXJAsDmH9/DoPJcCwH/Rc/9mz+zJW9YEiASuxl37e639erSFY3JwTTTOfnBzOoS4pWJPQtpCNdx77RXlSbNPyx+CgBMLpx5/QgqyLcBe0mWf2pA17eYHN3Z6gDt3Wsavg==" | ./build/linux/amd64/secretshare decrypt

The program then outputs:
Which outputs:

--- Below is the encrypted data ---

ptIDqdJTgu6SITIsWV/fM93RgkEeEn0TzAtZKy/sAo7I5SEwJ0UjrPCbZJNPX1skRRbUIUElNWepX37KG71zJfk41/bKg5q/PLq8bL5ZiGg4+PXld4zuPGZZShUJRWcL2+2/JQBi6qsvej1E2I1mf8EGkEd/rmnlFAoqxOgxCz7Y8Uu6RgP97PTvJQNFWyJEkNnAizb+RyXZyoQaTaZnSOr85DUdKSuOYEj6RLVLmpckTK6130NycMZlK5MjTWtzWlrmy45T1YXSxyrAPpnXjcWSxD6l0qbDCnflGmHaJ6CBtBnb8aYiCDFufzbGqW11ZGZaA/2GXvDjm5WFankLsA==

She sends this data to Bob, which copies and pastes the data into his terminal which was left running the sharesecret tool:

enter encrypted data
ptIDqdJTgu6SITIsWV/fM93RgkEeEn0TzAtZKy/sAo7I5SEwJ0UjrPCbZJNPX1skRRbUIUElNWepX37KG71zJfk41/bKg5q/PLq8bL5ZiGg4+PXld4zuPGZZShUJRWcL2+2/JQBi6qsvej1E2I1mf8EGkEd/rmnlFAoqxOgxCz7Y8Uu6RgP97PTvJQNFWyJEkNnAizb+RyXZyoQaTaZnSOr85DUdKSuOYEj6RLVLmpckTK6130NycMZlK5MjTWtzWlrmy45T1YXSxyrAPpnXjcWSxD6l0qbDCnflGmHaJ6CBtBnb8aYiCDFufzbGqW11ZGZaA/2GXvDjm5WFankLsA==

It then prints out the decrypted message:

-- start of message --
Here's your new password. Dont share it with anyone. I hope nobody decrypts this message. anyway it's "querty". Have fun.

-- end of message --
press ctrl-c to quit, or continue decoding more messages.

And there you have it!
Here's your new password. Dont share it with anyone. I hope nobody decrypts this message. anyway it's querty. Have fun.
Binary file modified build/darwin/amd64/secretshare
Binary file not shown.
Binary file modified build/linux/amd64/secretshare
Binary file not shown.
40 changes: 25 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,30 +169,40 @@ func genOrLoadKeys() (string, string, error) {

func main() {
test()
if len(os.Args) > 1 {
encryptMain(os.Args[1])
pub, priv, err := genOrLoadKeys()
pub = strings.TrimPrefix(pub, "ssh-rsa ")

if len(os.Args) <= 1 {
appName := "secret-share"
if len(os.Args) > 0 {
appName = os.Args[0]
}
fmt.Printf("To decrypt data, run: %s decrypt < file_to_decrypt\n", appName)
fmt.Printf("To encrypt data, run: %s <encryption_key> < data_to_encrypt\n", appName)
fmt.Printf("\n")
fmt.Printf("For example if someone wanted to send you data, they would run:\n%s %s < data_to_encrypt\n", appName, pub)
return
}

pub, priv, err := genOrLoadKeys()
arg := os.Args[1]

data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
pub = strings.TrimPrefix(pub, "ssh-rsa ")

fmt.Printf("run this command to encrypt data: %s %s\n", os.Args[0], pub)

for {
data := promptLine("enter encrypted data")
data2, err := decrypt(data, priv)
if arg == "decrypt" {
data2, err := decrypt(string(data), priv)
if err != nil {
fmt.Printf("failed to decrypt: %v\n", err)
continue
panic(err)
}
fmt.Println("")
fmt.Println("-- start of message --")
fmt.Println(data2)
fmt.Println("-- end of message --")
fmt.Println("press ctrl-c to quit, or continue decoding more messages.")
return
}

encrypted, err := encrypt(string(data), "ssh-rsa "+arg)
if err != nil {
panic(err)
}
fmt.Println(encrypted)
}

0 comments on commit 27f638a

Please sign in to comment.