diff --git a/s3cr3txGoTest.go b/s3cr3txGoTest.go index 59e2ec7..397f5cb 100644 --- a/s3cr3txGoTest.go +++ b/s3cr3txGoTest.go @@ -2,6 +2,7 @@ package main import ( //"crypto/tls" + "bufio" "fmt" "io/ioutil" "net/http" @@ -11,11 +12,34 @@ import ( func main() { fmt.Println("Hello, Thank you for testing s3cr3tx with Go") - var email string = "pk@gratitech.com" - var APIToken string = "bCrCgRrFoMKyw4PDkyoYF8O9PSXDrsKQRuKAueKAmTbDqsOdacOkw6/Dn8Kzw5/DvRTDjuKAusOyWG3DgG1oUMOBOcObfcOLDwpiwo06CcK2W8OHY3vDmkQzwqTCs1Mzwr/Cvg==" - var AuthCode string = "w4zCtm8fH1o7wr/DuB3FoeKAmDtfw5ZvwrLihKLigLA9XcOeMcKtHRYBy4Z5GhTDuMWgwqZoUsOnXR4hCsuG4oChV1HigLDDgMK4w6HFoTbDhlksw7gowrXDhsOMUMOKw4BmFg==" - var baseurl string = "https://s3cr3tx.com/Values" + fmt.Println("Please enter your input: ") + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + err := scanner.Err() + if err != nil { + fmt.Printf("client: could not read the input: %s\n", err) + } + var strInput = scanner.Text() + fmt.Println("Please enter 'e' to encrypt or 'd' to decrypt: ") + scanner2 := bufio.NewScanner(os.Stdin) + scanner2.Scan() + err2 := scanner2.Err() + if err != nil { + fmt.Printf("client: could not read the input: %s\n", err2) + } + var strDirection = scanner2.Text() + if strInput != "" && strDirection != "" { + var strOutput = io(strDirection, strInput) + fmt.Println(strOutput) + } + fmt.Println("Done with s3cr3tx Go Test!") +} +func io(strDirection string, strInput string) string { + var email string = "pk@gratitech.com" //"you@yourdomain.com" + var APIToken string = "yourS3cr3txAPIToken" + var AuthCode string = "yourS3cr3txAuthCode" + var baseurl string = "https://s3cr3tx.com/Values" req, err := http.NewRequest(http.MethodGet, baseurl, nil) if err != nil { fmt.Printf("client: could not create request: %s\n", err) @@ -26,8 +50,8 @@ func main() { req.Header.Set("Email", email) req.Header.Set("APIToken", APIToken) req.Header.Set("AuthCode", AuthCode) - req.Header.Set("EorD", "e") - req.Header.Set("Input", "This is something secret") + req.Header.Set("EorD", strDirection) + req.Header.Set("Input", strInput) client := http.Client{ Timeout: 30 * time.Second, } @@ -43,36 +67,13 @@ func main() { os.Exit(1) } - fmt.Println("Your encrypted text is : " + string(resBody)) - - req2, err := http.NewRequest(http.MethodGet, baseurl, nil) - if err != nil { - fmt.Printf("client: could not create request: %s\n", err) - os.Exit(1) - } - req2.Header.Set("Content-Type", "text/plain") - req2.Header.Set("Accept", "text/plain") - req2.Header.Set("Email", email) - req2.Header.Set("APIToken", APIToken) - req2.Header.Set("AuthCode", AuthCode) - req2.Header.Set("EorD", "d") - req2.Header.Set("Input", string(resBody)) - client2 := http.Client{ - Timeout: 30 * time.Second, - } - - res2, err := client2.Do(req2) - if err != nil { - fmt.Printf("client: error making http request: %s\n", err) - os.Exit(1) + if strDirection == "e" { + var strOutput = "Your encrypted text is : " + string(resBody) + return strOutput } - resBody2, err := ioutil.ReadAll(res2.Body) - if err != nil { - fmt.Printf("client: could not read response body: %s\n", err) - os.Exit(1) + if strDirection == "d" { + var strOutput = "Your decrypted text is : " + string(resBody) + return strOutput } - - fmt.Println("Your decrypted text is : " + string(resBody2)) - - fmt.Println("Done with s3cr3tx Go Test!") + return "" }