github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/utils/bdcrypto/base64.go (about)

     1  package bdcrypto
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/base64"
     6  	"io/ioutil"
     7  )
     8  
     9  // Base64Encode base64加密
    10  func Base64Encode(raw []byte) []byte {
    11  	var encoded bytes.Buffer
    12  	encoder := base64.NewEncoder(base64.StdEncoding, &encoded)
    13  	encoder.Write(raw)
    14  	encoder.Close()
    15  	return encoded.Bytes()
    16  }
    17  
    18  // Base64Decode base64解密
    19  func Base64Decode(raw []byte) []byte {
    20  	buf := bytes.NewReader(raw)
    21  	decoder := base64.NewDecoder(base64.StdEncoding, buf)
    22  	decoded, _ := ioutil.ReadAll(decoder)
    23  	return decoded
    24  }