From 68a6cf14450f24da6c127756f400e64595b90982 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Thu, 25 Nov 2021 00:25:28 +0800 Subject: [PATCH] fix: use url encode instead --- cmd/xorenc/main.go | 8 ++++---- go.mod | 2 +- xorencrypt.go | 6 +++--- xorencrypt_test.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/xorenc/main.go b/cmd/xorenc/main.go index 1402f1a..d427bb4 100644 --- a/cmd/xorenc/main.go +++ b/cmd/xorenc/main.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "kumoly.io/lib/xorencrypt" + "kumoly.io/lib/xorenc" ) var Version = "0.0.0" @@ -25,7 +25,7 @@ func main() { return } if len(os.Args) < 3 { - fmt.Println("usage: xorencrypt [e|d] msg key") + fmt.Println("usage: xorenc [e|d] msg key") os.Exit(1) } key := "" @@ -35,9 +35,9 @@ func main() { msg := os.Args[2] if strings.HasPrefix(os.Args[1], "e") { - fmt.Println(xorencrypt.Encrypt(msg, key)) + fmt.Println(xorenc.Encrypt(msg, key)) } else { - str, err := xorencrypt.Decrypt(msg, key) + str, err := xorenc.Decrypt(msg, key) if err != nil { panic(err) } diff --git a/go.mod b/go.mod index 1e378cd..2d94864 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module kumoly.io/lib/xorencrypt +module kumoly.io/lib/xorenc go 1.17 diff --git a/xorencrypt.go b/xorencrypt.go index fee216e..bce0849 100644 --- a/xorencrypt.go +++ b/xorencrypt.go @@ -1,4 +1,4 @@ -package xorencrypt +package xorenc import "encoding/base64" @@ -8,7 +8,7 @@ func Decrypt(msg, key string) (string, error) { if key == "" { key = DEFAULT_KEY } - deb64, err := base64.StdEncoding.DecodeString(msg) + deb64, err := base64.URLEncoding.DecodeString(msg) if err != nil { return "", err } @@ -21,7 +21,7 @@ func Encrypt(msg, key string) string { key = DEFAULT_KEY } enc := xor([]byte(msg), []byte(key)) - return base64.StdEncoding.EncodeToString(enc) + return base64.URLEncoding.EncodeToString(enc) } func xor(msg, key []byte) []byte { diff --git a/xorencrypt_test.go b/xorencrypt_test.go index 149fa8e..17fea41 100644 --- a/xorencrypt_test.go +++ b/xorencrypt_test.go @@ -1,4 +1,4 @@ -package xorencrypt +package xorenc import ( "fmt"