Tutorial by Examples

const foobar = `foo bar` encoding := base64.StdEncoding encodedFooBar := make([]byte, encoding.EncodedLen(len(foobar))) encoding.Encode(encodedFooBar, []byte(foobar)) fmt.Printf("%s", encodedFooBar) // Output: Zm9vIGJhcg== Playground
str := base64.StdEncoding.EncodeToString([]byte(`foo bar`)) fmt.Println(str) // Output: Zm9vIGJhcg== Playground
encoding := base64.StdEncoding data := []byte(`Zm9vIGJhcg==`) decoded := make([]byte, encoding.DecodedLen(len(data))) n, err := encoding.Decode(decoded, data) if err != nil { log.Fatal(err) } // Because we don't know the length of the data that is encoded // (only the max length), we n...
decoded, err := base64.StdEncoding.DecodeString(`biws`) if err != nil { log.Fatal(err) } fmt.Printf("%s", decoded) // Output: n,, Playground

Page 1 of 1