我有蜜蜂试图解码从其他系统返回的一些字符串,但如果我使用在线解码器或使用 PHP 解码,解码后的字符串会有不同的结果。我一直在尝试使用base64.StdEncoding.DecodeString()andbase64.StdEncoding.Decode()但结果仍然与在线解码器或 PHP 代码的结果不同。
这是我的代码:
// encoded string
s := "HxJVICMcHCYeHUJcEWISWk09JgxHBwRPXHlHWFoGf1JXCkgFS1xXVU9Ze1FSCUwUIFMdGx0-SglVDmRNUHdAJRETRR0hHx0aIB1OExcgUCkeRyEaDUE5Y1oTREhcCRJSXAtWHBwfJSUYFUALUFd-VlkIU0JYFg5TA04PURA_OFBQXHpXWVxTSEZlC1FZTH4TKTUXGx1ORBcfSB0fO0xRJRoRVxsmExcoIhxEAxsQfF9bD1tXSQd-XEkBShEoPH80UWEJWAhAQhA0XgNVTwdWZxEX"
// add '=' on the right string
strHelper := string2.NewStringHelper()
sl := math.Ceil(float64(len(s) / 4 * 4))
sp := strHelper.StrPadRight(s, "=", int(sl))
sp = strtr(sp, map[string]string{"-_": "+/"})
// decode the string using base64.StdEncoding.DecodeString()
spb, _ := base64.StdEncoding.DecodeString(sp)
// decode the string using base64.StdEncoding.Decode()
b64 := make([]byte, base64.StdEncoding.DecodedLen(len(sp)))
n, err := base64.StdEncoding.Decode(b64, []byte(sp))
// decode the string using base64.NewDecoder()
b64s := strings.NewReader(sp)
b64d := base64.NewDecoder(base64.StdEncoding, b64s)
buf := new(strings.Builder)
io.Copy(buf, b64d)
// result of decoded string
U #&B\bZM=&GO\yGXZRW
HK\WUOY{QR L S
// result from online decoder or PHP
U #&B\bZM=&GO\yGXZRW
HK\WUOY{QR L S>J UdMPw@%E! N P)G!
A9cZDH\ R\V%%@PW~VYSBXSNQ?8PP\zWY\SHFeQYL~)5NDH;LQ%W&("D|_[[WI~\IJ(<4Qa X@B4^UOVg
https://go.dev/play/p/Yqf2I2QgWxS
请有人启发我我的代码哪里错了?
慕丝7291255
相关分类