From 7a5325187a456f5ff2efdadc37536478b049b828 Mon Sep 17 00:00:00 2001 From: nite07 Date: Tue, 19 Mar 2024 03:33:25 +0800 Subject: [PATCH] add: url safe base64 --- internal/base64.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/base64.go b/internal/base64.go index 1cdd891..c12bfba 100644 --- a/internal/base64.go +++ b/internal/base64.go @@ -7,6 +7,11 @@ import ( func DecodeBase64(s string) (string, error) { s = strings.TrimSpace(s) + // url safe + if strings.Contains(s, "-") || strings.Contains(s, "_") { + s = strings.Replace(s, "-", "+", -1) + s = strings.Replace(s, "_", "/", -1) + } if len(s)%4 != 0 { s += strings.Repeat("=", 4-len(s)%4) }