From a8263b543cc3c779c7e20ba143994d638e3b7143 Mon Sep 17 00:00:00 2001 From: ghosind Date: Sun, 21 Jul 2024 03:25:41 +0800 Subject: [PATCH] xsrftoken: create no padding base64 string by RawURLEncoding. Getting the no padding base64 string with base64.RawURLEncoding to reduce the costs. --- xsrftoken/xsrf.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xsrftoken/xsrf.go b/xsrftoken/xsrf.go index 3ca5d5b9f..e808e6dd8 100644 --- a/xsrftoken/xsrf.go +++ b/xsrftoken/xsrf.go @@ -45,10 +45,9 @@ func generateTokenAtTime(key, userID, actionID string, now time.Time) string { h := hmac.New(sha1.New, []byte(key)) fmt.Fprintf(h, "%s:%s:%d", clean(userID), clean(actionID), milliTime) - // Get the padded base64 string then removing the padding. + // Get the no padding base64 string. tok := string(h.Sum(nil)) - tok = base64.URLEncoding.EncodeToString([]byte(tok)) - tok = strings.TrimRight(tok, "=") + tok = base64.RawURLEncoding.EncodeToString([]byte(tok)) return fmt.Sprintf("%s:%d", tok, milliTime) }