gf/g/encoding/gbase64/gbase64.go

24 lines
628 B
Go
Raw Normal View History

// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
2017-12-29 16:03:30 +08:00
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
2017-12-29 16:03:30 +08:00
2019-01-15 23:27:47 +08:00
// Package gbase64 provides useful API for BASE64 encoding/decoding algorithms.
2017-11-23 10:21:28 +08:00
package gbase64
import (
2019-06-19 09:06:52 +08:00
"encoding/base64"
2017-11-23 10:21:28 +08:00
)
// base64 encode
func Encode(str string) string {
2019-06-19 09:06:52 +08:00
return base64.StdEncoding.EncodeToString([]byte(str))
2017-11-23 10:21:28 +08:00
}
// base64 decode
func Decode(str string) (string, error) {
2019-06-19 09:06:52 +08:00
s, e := base64.StdEncoding.DecodeString(str)
return string(s), e
}