fix: use url encode instead
continuous-integration/drone/tag Build is passing Details

master v0.1.1
Evan Chen 2021-11-25 00:25:28 +08:00
parent 220dd90b01
commit 68a6cf1445
4 changed files with 9 additions and 9 deletions

View File

@ -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)
}

2
go.mod
View File

@ -1,3 +1,3 @@
module kumoly.io/lib/xorencrypt
module kumoly.io/lib/xorenc
go 1.17

View File

@ -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 {

View File

@ -1,4 +1,4 @@
package xorencrypt
package xorenc
import (
"fmt"