2023-09-12 06:40:24 -04:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2023-09-24 02:48:42 -04:00
|
|
|
"strings"
|
2023-09-12 06:40:24 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func DecodeBase64(s string) (string, error) {
|
2023-09-24 02:48:42 -04:00
|
|
|
s = strings.TrimSpace(s)
|
2024-08-11 11:55:47 -04:00
|
|
|
|
2024-04-23 02:39:16 -04:00
|
|
|
if strings.Contains(s, "-") || strings.Contains(s, "_") {
|
|
|
|
s = strings.Replace(s, "-", "+", -1)
|
|
|
|
s = strings.Replace(s, "_", "/", -1)
|
|
|
|
}
|
2023-09-24 02:48:42 -04:00
|
|
|
if len(s)%4 != 0 {
|
|
|
|
s += strings.Repeat("=", 4-len(s)%4)
|
|
|
|
}
|
2023-09-12 06:40:24 -04:00
|
|
|
decodeStr, err := base64.StdEncoding.DecodeString(s)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(decodeStr), nil
|
|
|
|
}
|