From 2d2dcb198cd4f7d5ea1ab2971efbbb8919075c18 Mon Sep 17 00:00:00 2001 From: esonhugh Date: Tue, 7 Dec 2021 12:03:25 +0800 Subject: [PATCH] feat(str): add b64 string to string func. --- utils/str.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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))