douhui3305 2017-02-26 18:56
浏览 74
已采纳

GOLANG 64decode字符串非法数据,不确定为什么

Fellow Gophers:

I'm stuck on something simple. I'm trying to convert decode a 64endoded string (OAUTH token to be exact).

I split the string, and put one of the parts of the split to be 64decoded, and I always find an illegal character. When I put the same value into any web based 64decoder it works.

I think that maybe there is a trailing null or something. Can anyone give me some advice. I put the code here: https://play.golang.org/p/cf-x6GgpEp

The exact error is: illegal base64 data at input byte 408

Below is the code as well, its pretty short:

package main

import (
    "fmt"
    "strings"
    b64 "encoding/base64"
)

func main() {

    fmt.Println("Hello, playground and stackover flow users")


    token := `eyJhbGciOiJSUzI1NiIsImtpZCI6IkNKc2hmNnhMOGVuODlhVVZVenJaX1JqMTJwS3pqZkFUdkNqcT    lNbUxGTlUifQ.eyJ2ZXIiO
jEsImp0aSI6IkFULlFxN21mck94RnhZaVFXZWpGQjczMTZnRXdQbWJBVGtsVzB6Sm1FWVRPU0UiLCJp    c3MiOiJodHRwczovL2Nvb
XBhbnl4Lm9rdGEuY29tL29hdXRoMi9hdXMxYTRpYmRhdDBKWXc1czFkOCIsImF1ZCI6Imh0dHA6Ly9s    b2NhbGhvc3Q6MzAwMCIsI
mlhdCI6MTQ4ODA2MDgxMywiZXhwIjoxNDg4MDY0NDEzLCJjaWQiOiIzam1OdlZDRlo1RjZsV096SU9O    TyIsInVpZCI6IjAwdTFhOXNrMXloenR3Y3FSMWQ4Iiwic2NwIjpbInJlYWQiLCJyZW1vdmUiLCJyZXN    lcnZlIl0sInN1YiI6InJlbW92ZUB3b3cuY29tIn0
.XFGZoVv-w4kRgqMDB-Me1RM1aO5f5JH8W_fLFGnYzkLXGassbKMWafAfVx9j-    wzaWVFfHtsH4fiLjZZbCRYkWli0b6Q3VjdDPJq
YcvhN_wQ9WTmqoJLNyY-    AA5o7yThL4Vz5ih7P_nJWMN7xEWUpWadeJbShvPNtdFHHPBFTAiDx0fXFs98vZHfeLEy2dnwYf4aY4p    w
jcfmhOZNaVahMtQh0dJVa0ai4KPMqQXDXMHDrbEwa2eWY_2pCPXUZekvC3DyRFeSfkRJ6fIe3d6XccDgAy_qzjBCjnutyezg7ZzV
d866wkb2j2kJwyr0w3Q5iBBFgxEv6vpcpaM_KHSXTyA`


// Spit the token to get the middle value xx.(we want this).xx



 fragments := strings.Split(token,".")
fmt.Println ( "Here is the value
"+fragments[1])

jwtFragment, err := b64.StdEncoding.DecodeString(fragments[1])
_=jwtFragment //

fmt.Println (err)

fmt.Println ("any ideas")

}

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在数字信号处理中用MATLAB显示波形。
      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM
      • ¥20 请问有没有RTL8211FS的参考原理图
      • ¥50 esp32的platfromio工程添加文件就会编译失败
      • ¥15 linux下运行VASP报错
      • ¥15 python里面查找赋值,如何可以在剩余未空值的行里面进行进一步的筛选呢?
      • ¥15 电路分析的综合实验有没有会的
      • ¥15 #硬件设计#PNP三级管输出设计问题