Encode/Decode base64

前端 未结 5 1084
陌清茗
陌清茗 2021-02-06 22:06

here is my code and i don\'t understand why the decode function doesn\'t work.

Little insight would be great please.

func EncodeB64(message string) (reto         


        
5条回答
  •  我寻月下人不归
    2021-02-06 22:44

    DecodedLen returns the maximal length.

    This length is useful for sizing your buffer but part of the buffer won't be written and thus won't be valid UTF-8.

    You have to use only the real written length returned by the Decode function.

    l, _ := base64.StdEncoding.Decode(base64Text, []byte(message))
    log.Printf("base64: %s\n", base64Text[:l])
    

提交回复
热议问题