You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
572 B
31 lines
572 B
package crypto
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"strings"
|
|
)
|
|
|
|
// Base64Encode
|
|
func (c *Crypto) Base64Encode(str string) string {
|
|
byteStr := []byte(str)
|
|
return base64.StdEncoding.EncodeToString(byteStr)
|
|
}
|
|
|
|
// Base64Decode
|
|
func (c *Crypto) 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
|
|
}
|