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")
}