1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 15:14:43 -05:00
sub2clash/parser/base64.go
2024-08-11 23:55:47 +08:00

24 lines
457 B
Go

package parser
import (
"encoding/base64"
"strings"
)
func DecodeBase64(s string) (string, error) {
s = strings.TrimSpace(s)
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)
}
decodeStr, err := base64.StdEncoding.DecodeString(s)
if err != nil {
return "", err
}
return string(decodeStr), nil
}