diff --git a/utils/str.go b/utils/str.go index b27a421..760365a 100644 --- a/utils/str.go +++ b/utils/str.go @@ -4,11 +4,24 @@ import ( "crypto/hmac" "crypto/md5" "crypto/sha1" + "encoding/base64" "encoding/hex" "fmt" "io" ) +func B64encode(content string) string { + return base64.StdEncoding.EncodeToString([]byte(content)) +} + +func B64decode(content string) (string, error) { + data, err := base64.StdEncoding.DecodeString(content) + if err != nil { + return "", err + } + return string(data), nil +} + func Sha1(content string) string { h := sha1.New() h.Write([]byte(content))