Implement base64_decode in GO language to solve the problem of illegal characters

When using the base64 decode of the standard library, there will be an error of illegal characters. The following function is my test and it can be decrypted normally.

Pay attention to this parameter: base64.RawStdEncoding is the key to solving illegal characters

func Base64Decode(str string ) string {
    reader: = strings.NewReader(str)
    decoder: = base64.NewDecoder(base64.RawStdEncoding, reader)
     // Decoding 
    buf in streaming mode := make([] byte , 1024 )
     // Save the decoded data 
    dst := "" 
    for {
        n, err : = decoder.Read(buf)
        dst += string (buf[:n])
         if n == 0 || err != nil {
             break
        }
    }
    return dst
}


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *