2022-09-27 11:31:23 +08:00
|
|
|
/**
|
|
|
|
* @Author: Echo
|
|
|
|
* @Author:1711788888@qq.com
|
|
|
|
* @Date: 2021/5/27 19:15
|
|
|
|
* @Desc: BASE64
|
|
|
|
*/
|
|
|
|
|
|
|
|
package sign
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-11-02 14:57:22 +08:00
|
|
|
func base64urlEncode(data []byte) string {
|
2022-09-27 11:31:23 +08:00
|
|
|
str := base64.StdEncoding.EncodeToString(data)
|
|
|
|
str = strings.Replace(str, "+", "*", -1)
|
|
|
|
str = strings.Replace(str, "/", "-", -1)
|
|
|
|
str = strings.Replace(str, "=", "_", -1)
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2022-11-02 14:57:22 +08:00
|
|
|
func base64urlDecode(str string) ([]byte, error) {
|
2022-09-27 11:31:23 +08:00
|
|
|
str = strings.Replace(str, "_", "=", -1)
|
|
|
|
str = strings.Replace(str, "-", "/", -1)
|
|
|
|
str = strings.Replace(str, "*", "+", -1)
|
|
|
|
return base64.StdEncoding.DecodeString(str)
|
|
|
|
}
|