2023-09-12 18:40:24 +08:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
2023-09-24 14:48:42 +08:00
|
|
|
"strings"
|
2023-09-12 18:40:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func DecodeBase64(s string) (string, error) {
|
2023-09-24 14:48:42 +08:00
|
|
|
s = strings.TrimSpace(s)
|
|
|
|
if len(s)%4 != 0 {
|
|
|
|
s += strings.Repeat("=", 4-len(s)%4)
|
|
|
|
}
|
2023-09-12 18:40:24 +08:00
|
|
|
decodeStr, err := base64.StdEncoding.DecodeString(s)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(decodeStr), nil
|
|
|
|
}
|