gmessages/libgm/crypto/B64.go

42 lines
815 B
Go
Raw Normal View History

2023-06-30 09:54:08 +00:00
package crypto
import (
"encoding/base64"
"fmt"
"strings"
)
func EncodeBase64Standard(data []byte) string {
return base64.StdEncoding.EncodeToString(data)
}
func EncodeBase64(data []byte) string {
return base64.RawURLEncoding.EncodeToString(data)
}
func Base64Decode(input string) ([]byte, error) {
2023-06-30 09:55:49 +00:00
padding := len(input) % 4
if padding > 0 {
input += strings.Repeat("=", 4-padding)
}
2023-06-30 09:54:08 +00:00
2023-06-30 09:55:49 +00:00
data, err := base64.URLEncoding.DecodeString(input)
if err != nil {
return nil, err
}
return data, nil
2023-06-30 09:54:08 +00:00
}
func Base64DecodeStandard(input string) ([]byte, error) {
2023-06-30 09:55:49 +00:00
decoded, err := base64.StdEncoding.DecodeString(input)
if err != nil {
fmt.Println("decode error:", err)
return nil, err
}
return decoded, nil
2023-06-30 09:54:08 +00:00
}
func Base64Encode(input []byte) string {
return base64.StdEncoding.EncodeToString(input)
2023-06-30 09:55:49 +00:00
}