在使用标准库的base64 decode时会出现非法字符的错误 , 下面这个函数是我测试可以正常解密的

注意这个参数 :  base64.RawStdEncoding  是解决非法字符的关键

func Base64Decode(str string) string {
    reader := strings.NewReader(str)
    decoder := base64.NewDecoder(base64.RawStdEncoding, reader)
    // 以流式解码
    buf := make([]byte, 1024)
    // 保存解码后的数据
    dst := ""
    for {
        n, err := decoder.Read(buf)
        dst += string(buf[:n])
        if n == 0 || err != nil {
            break
        }
    }
    return dst
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2021-09-16
  • 2021-10-26
  • 2021-09-29
  • 2022-12-23
  • 2023-03-19
相关资源
相似解决方案