1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 import "encoding/base64"
9 const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
11 var bcEncoding = base64.NewEncoding(alphabet)
13 func base64Encode(src []byte) []byte {
14 n := bcEncoding.EncodedLen(len(src))
15 dst := make([]byte, n)
16 bcEncoding.Encode(dst, src)
23 func base64Decode(src []byte) ([]byte, error) {
24 numOfEquals := 4 - (len(src) % 4)
25 for i := 0; i < numOfEquals; i++ {
26 src = append(src, '=')
29 dst := make([]byte, bcEncoding.DecodedLen(len(src)))
30 n, err := bcEncoding.Decode(dst, src)