本文整理汇总了Golang中encoding/base64.NewEncoding函数的典型用法代码示例。如果您正苦于以下问题:Golang NewEncoding函数的具体用法?Golang NewEncoding怎么用?Golang NewEncoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewEncoding函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Init
func (this *PrePackModule) Init(global_conf *context.GlobalContext) (err error) {
this.click_head = global_conf.Prepack.ClickHeader
this.win_head = global_conf.Prepack.WinHeader
this.common_head = global_conf.Prepack.CommonHeader
utils.DebugLog.Write("Prepack.ClickHeader [%s]", this.click_head)
utils.DebugLog.Write("Prepack.WinHeader [%s]", this.win_head)
base64_code := [64]string{"0Ge5Q6wnuBML3Wg-8s7kAjOr2xohRHif1CczEXDKq_VaUPJdYpy9TSNvIFmbZ4tl", "1RPspa70TiZum_6tKNIFOVJ4o3gBGkdLlvhCnQHWDxEA5cq8fYzj2XU9MwrS-ybe", "2txfHr4BFaqSOTVn_CuYozeygvbcL1RNKs8MkWUPG0JpmXd5l6hDIAjw7i9E-Q3Z", "3c5gtSlVFoEXsehLaMJwI0Rv6U7xmWuzCYABP_TDp-QfdKniNrq2Ob419jHkGZy8", "456tTGIcm3EK7_RQpBA2uezWXjqnHPsi9bV-Zx8vSgkwaMlCoJ1DyfLFr0UYNhdO", "5zDkOUe_q7a2TN-Y3fvrnsCHZxhBIdcESPj8GuWXLgib4QwJo6yVtMF0Kp1mA9Rl", "6bgkOJjx8mPI9Y_hWANypSoFtnDadivQ31crfR0uC-K2qzE4UslMXGBTL5Vw7HeZ", "7zXOg9UZp0sa2vWGJP3TCBYR-6eIfHVnmdKwMrbuSlo8LFNthAkqcDy4QxE5ji1_", "8iMsWOQuApUEhoITJfjbYdLqrcF3m17XwNa_B4lVSC-Deny0KPtG6z2k5gx9vZHR", "9gdocC-fpejPiYnHF7l0XrWUAaS3OI_Nm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et-2", "XYc4wekTRE8ZoxQ9dtiyO-3aAfuIjVsCFh_7Jp20rqm5SHWL1lBbnUNzDKvGPMg6", "YHS9KRLhdqbMtaeX6wG4QNp21sBFrIV_y7DlCzOx80UiumWAnT5-PkgocJEf3jZv", "Z_FmazrYTKXHW-4sSbk86D5VPyfN13gBu9deJE7q2ontjQOGhxwiCclUAMvLp0IR", "_rJb0Up6R2hNDWFAH3LswnYd7zPQo1M8KxyIjBugESqTGZtmleifcVkCX9v5-aO4", "-6mTYvy7KRxCr2elEiWbL5qMoc9G1_3untsdpjwDAzFVhZSgBN0aIOU4QkH8fJXP"}
for i := 0; i < len(base64_code); i++ {
this.coder[i] = base64.NewEncoding(base64_code[i])
}
code_char := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
this.basecoder = base64.NewEncoding(code_char)
this.texttpl, err = template.ParseFiles(global_conf.Template.Texttpl)
utils.DebugLog.Write("get texttpl [%s]", global_conf.Template.Texttpl)
if err != nil || this.texttpl == nil {
utils.FatalLog.Write("load texttpl fail, err[%s]", err.Error())
return
}
this.imgtpl, err = template.ParseFiles(global_conf.Template.Imagetpl)
utils.DebugLog.Write("get imagetpl [%s]", global_conf.Template.Imagetpl)
if err != nil || this.imgtpl == nil {
utils.FatalLog.Write("load imagetpl fail, err[%s]", err.Error())
return
}
this.icontexttpl, err = template.ParseFiles(global_conf.Template.Icontexttpl)
utils.DebugLog.Write("get icontpl [%s]", global_conf.Template.Icontexttpl)
if err != nil || this.icontexttpl == nil {
utils.FatalLog.Write("load icontexttpl fail, err[%s]", err.Error())
return
}
this.texttpl_rec, err = template.ParseFiles(global_conf.Template.Texttplrec)
utils.DebugLog.Write("get texttpl_rec [%s]", global_conf.Template.Texttplrec)
if err != nil || this.texttpl_rec == nil {
utils.FatalLog.Write("load txttpl_rec fail . err[%s]", err.Error())
return
}
this.imgtpl_rec, err = template.ParseFiles(global_conf.Template.Imagetplrec)
utils.DebugLog.Write("get texttpl_rec [%s]", global_conf.Template.Imagetplrec)
if err != nil || this.imgtpl_rec == nil {
utils.FatalLog.Write("load imagetpl_rec fail . err[%s]", err.Error())
return
}
this.icontpl_rec, err = template.ParseFiles(global_conf.Template.Icontplrec)
utils.DebugLog.Write("get icontpl_rec [%s]", global_conf.Template.Icontplrec)
if err != nil || this.icontpl_rec == nil {
utils.FatalLog.Write("load icontpl_rec fail . err[%s]", err.Error())
return
}
/* this.recommendtpl, err = template.ParseFiles(global_conf.Template.Recommendtpl)
if err != nil || this.imgtpl == nil {
return
}*/
return
}
开发者ID:ifzz,项目名称:seller_adptor,代码行数:54,代码来源:prepack.go
示例2: HandshakeOfWS
//for a websocket connection this function funcs as handshaking
//apply websocket protocal to establish a connection
func HandshakeOfWS(conn net.Conn) error {
b := make([]byte, 1024)
a := make([]byte, 1024)
n, err := conn.Read(a)
b = append(b, a[:n]...)
if err != nil {
if err == io.EOF {
} else {
return errors.New("error happen when read from connection!")
}
}
re, err := regexp.Compile("Sec-WebSocket-Key: (.*)\r\n")
if checkErr(err) {
return errors.New("regexp error!")
}
result := re.FindStringSubmatch(string(b))
if result == nil {
return errors.New("not right format!")
}
key_tmp := append([]byte(result[1]), []byte(mask)...)
key_tmp_tmp := sha1.Sum(key_tmp)
encoder := base64.NewEncoding(base64Table)
dst := make([]byte, 1024)
encoder.Encode(dst, key_tmp_tmp[:])
reply := "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + string(dst) + "\r\n\r\n"
conn.Write([]byte(reply))
return nil
}
开发者ID:muyizixiu,项目名称:commonOperation,代码行数:32,代码来源:h.go
示例3: SendToEvernote
func SendToEvernote(from, to, subject, body string) error {
hp := strings.Split(EmailSrv, ":")
auth := smtp.PlainAuth("", EmailUsr, EmailPwd, hp[0])
subject = erasebractket(subject)
tmpsubject := subject
subidx := 0
for len(tmpsubject) > 0 {
_, size := utf8.DecodeRuneInString(tmpsubject)
if subidx+size > 70 {
break
}
subidx += size
tmpsubject = tmpsubject[size:]
}
subject = subject[:subidx]
subject = strings.Replace(subject, "@", "", -1)
subject += " @股市"
log.Println("SendToEvernote", from, subject, to)
b64 := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
msg := []byte("To: " + to + "\r\nFrom: " + "xhbot" + "<" + EmailUsr + ">\r\nSubject: " + encodeRFC2047(subject) + "\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: text/html; charset=UTF-8 \r\nContent-Transfer-Encoding: base64\r\n\r\n" + b64.EncodeToString([]byte(body)))
send_to := strings.Split(to, "|")
err := smtp.SendMail(EmailSrv, auth, EmailUsr, send_to, msg)
return err
}
开发者ID:2qif49lt,项目名称:golang,代码行数:31,代码来源:xueqiuqqnotify.go
示例4: SignPolicy
// SignPolicy return the proper signature and other parameters needed to
// generate a valid Cloudfront Signed URL.
// For canned policies this is: Expires, Signature, Key-Pair-Id
// For custom policies this is: Policy, Signature, Key-Pair-Id
//
// More information:
// http://goo.gl/pvA97e
// Command line equivalent:
// cat policy | openssl sha1 -sign cloudfront-keypair.pem | openssl base64 | tr '+=/' '-_~'
func SignPolicy(privateKey PrivateKey, policy PolicySigner, keyPairID string) (string, error) {
signature, err := policy.signWithPrivateKey(privateKey)
if err != nil {
return "", fmt.Errorf("Cannot sign policy: %v", err)
}
encoding := base64.NewEncoding(encodeCloudFront)
paddingMap := func(r rune) rune {
switch r {
case '=':
return '_'
default:
return r
}
}
switch policy.(type) {
case CannedPolicy:
return fmt.Sprintf("Expires=%d&Signature=%s&Key-Pair-Id=%s",
policy.(CannedPolicy).ExpiresAt.Unix(),
strings.Map(paddingMap, encoding.EncodeToString(signature)),
keyPairID,
), nil
case CustomPolicy:
return fmt.Sprintf("Policy=%s&Signature=%s&Key-Pair-Id=%s",
strings.Map(paddingMap, encoding.EncodeToString([]byte(policy.String()))),
strings.Map(paddingMap, encoding.EncodeToString(signature)),
keyPairID,
), nil
}
return "", nil
}
开发者ID:soundcloud,项目名称:sc-gaws,代码行数:41,代码来源:signature.go
示例5: encodeBytes
func encodeBytes(b []byte) (s string) {
// Note that this encoding is not decodable, as we are using '0' for two different bytes.
// This is much safer for using these as parts of file names.
enc := base64.NewEncoding("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0")
s = enc.EncodeToString(b)
return
}
开发者ID:rhettg,项目名称:ftl,代码行数:7,代码来源:util.go
示例6: main
func main() {
host := "192.168.0.243:25"
from := mail.Address{"发件人", "[email protected]"}
to := mail.Address{"收件人", "[email protected]"}
header := make(map[string]string)
header["From"] = from.String()
header["To"] = to.String()
b64 := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
header["Subject"] = fmt.Sprintf("=?UTF-8?B?%s?=", b64.EncodeToString([]byte("标题测试")))
header["MIME-Version"] = "1.0"
header["Content-Type"] = "text/html; charset=UTF-8"
header["Content-Transfer-Encoding"] = "base64"
body := "邮件正文"
message := ""
for k, v := range header {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + b64.EncodeToString([]byte(body))
//auth := smtp.PlainAuth("", "", "", host)
err := smtp.SendMail(host, nil, "[email protected]", []string{to.Address}, []byte(message))
fmt.Println(err)
}
开发者ID:tzm529,项目名称:studygo,代码行数:26,代码来源:sendmail.go
示例7: HandleConnection
func (ca *ConnectionAcceptor) HandleConnection(conn net.Conn) {
err := conn.(*tls.Conn).Handshake()
if err != nil {
log.Print("New connection failed during Handshake")
log.Print(err)
} else {
state := conn.(*tls.Conn).ConnectionState()
if len(state.PeerCertificates) == 0 {
log.Print("New connection failed: no certificate present")
conn.Close()
return
}
hash := sha1.New()
hash.Write(state.PeerCertificates[0].Raw)
sha1hash := hash.Sum(nil)
encoder := base64.NewEncoding("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/")
hashstring := encoder.EncodeToString(sha1hash)
if hashstring == ca.Myhash {
log.Print("New admin connection")
ca.out <- NewEvent("NewAdminConnection", conn)
} else {
ci := &UnauthConnectionInfo{conn, hashstring}
event := NewEvent("NewUnauthenticatedConnection", ci)
//log.Print("New unauthenticated connection")
ca.out <- event
}
}
}
开发者ID:spartacus23,项目名称:cobweb,代码行数:28,代码来源:ConnectionAcceptor.go
示例8: Base64Encode
func Base64Encode(values []byte) string {
if base64Encoding == nil {
base64Encoding = base64.NewEncoding(base64CodeTbl)
}
return base64Encoding.EncodeToString(values)
}
开发者ID:xioxu,项目名称:aliyun-openapi-go-sdk,代码行数:7,代码来源:parameterHelper.go
示例9: genPw
func genPw(master, siteName, alphabet string) (string, error) {
if m, _ := regexp.MatchString("[^uns]+", alphabet); m {
return "", errors.New(fmt.Sprintf("Alphabet string %s makes no sense", alphabet))
}
encodeString := ""
if strings.Contains(alphabet, "u") {
encodeString += "QWERTYUIOPASDFGHJKLZXCVBNM"
}
if strings.Contains(alphabet, "n") {
encodeString += "1234567890"
}
if strings.Contains(alphabet, "s") {
encodeString += "[email protected]#$%^&*()~`{}[];:<>,.?/"
}
encodeString += genLowers(64 - len(encodeString))
encoder := base64.NewEncoding(encodeString)
c1 := sha256.Sum256([]byte(master + siteName))
s1 := encoder.EncodeToString(c1[:12])
return s1, nil
}
开发者ID:hallliu,项目名称:pwgen,代码行数:25,代码来源:pwgen.go
示例10: Base64Decode
func Base64Decode(fileContent string) (string, error) {
b64 := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
decodeBytes, err := b64.DecodeString(fileContent)
if err != nil {
return "", err
}
return string(decodeBytes), nil
}
开发者ID:kkpapa,项目名称:hyper,代码行数:8,代码来源:utils.go
示例11: randString
func randString(l int) string {
encoding := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB"
b := make([]byte, l)
rand.Read(b)
enc := base64.NewEncoding(encoding)
d := make([]byte, enc.EncodedLen(len(b)))
enc.Encode(d, b)
d = d[:l]
return string(d)
}
开发者ID:Festum,项目名称:go-mega,代码行数:10,代码来源:utils.go
示例12: base64Decode
func base64Decode(data string) ([]byte, error) {
base := base64.NewEncoding(validEncoding)
if len(data)%4 == 1 && data[len(data)-1] == 'A' {
return base.DecodeString(string(data[:len(data)-1]))
}
if len(data)%4 != 0 {
data = data + strings.Repeat("=", (4-(len(data)%4)))
}
return base.DecodeString(data)
}
开发者ID:nickvanw,项目名称:bogon,代码行数:10,代码来源:dh1080.go
示例13: generate
func generate(secretpassword, sitename string) string {
input := []byte(secretpassword + ":" + sitename)
pwd := &bytes.Buffer{}
encoder := base64.NewEncoder(base64.NewEncoding("ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz123456789?!#@&$"), pwd)
h := sha1.New()
h.Write(input)
s := h.Sum(nil)
encoder.Write(s)
encoder.Close()
return ensurenumberandletter(pwd.String()[:10])
}
开发者ID:strangelight,项目名称:shelleon,代码行数:11,代码来源:main.go
示例14: main
func main() {
s := "Love is but a song to sing Fear's the way we die You can make the mountains ring Or make the angels cry Though the bird is on the wing And you may not know why Come on people now Smile on your brother Everybody get together Try to love one another Right now"
encodeStd := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
s64 := base64.NewEncoding(encodeStd).EncodeToString([]byte(s))
fmt.Println(len(s))
fmt.Println(len(s64))
fmt.Println(s)
fmt.Println(s64)
}
开发者ID:GoesToEleven,项目名称:golang-web,代码行数:11,代码来源:main.go
示例15: Configure
// Configure initializes this formatter with values from a plugin config.
func (format *Base64Decode) Configure(conf core.PluginConfig) error {
dict := conf.GetString("Dictionary", "")
if dict == "" {
format.dictionary = base64.StdEncoding
} else {
if len(dict) != 64 {
return fmt.Errorf("Base64 dictionary must contain 64 characters.")
}
format.dictionary = base64.NewEncoding(dict)
}
return nil
}
开发者ID:oopcode,项目名称:gollum,代码行数:13,代码来源:base64decode.go
示例16: init
func init() {
gob.Register((*peony.Session)(nil))
peony.OnServerInit(func(s *peony.Server) {
sec := s.App.Security
encoding = base64.NewEncoding(sec)
s.RegisterSessionManager(&SimpleSessionManager{})
CookieHttpOnly = s.App.GetBoolConfig("CookieHttpOnly", false)
CookieSecure = s.App.GetBoolConfig("CookieSecure", false)
SessionTimeout = s.App.GetIntConfig("SessionTimeout", 30)
})
}
开发者ID:Joinhack,项目名称:peony,代码行数:12,代码来源:session.go
示例17: base64Encode
func base64Encode(data []byte) (string, error) {
if len(data) < 1 {
return "", errors.New("Zero Length String")
}
base := base64.NewEncoding(validEncoding)
encodedString := base.EncodeToString(data)
if !strings.Contains(encodedString, "=") {
encodedString += "A"
} else {
encodedString = strings.TrimRight(encodedString, "=")
}
return encodedString, nil
}
开发者ID:nickvanw,项目名称:bogon,代码行数:13,代码来源:dh1080.go
示例18: SendMail
func (this *Smtp) SendMail(from, tos, subject, body string, contentType ...string) error {
if this.Address == "" {
return fmt.Errorf("address is necessary")
}
hp := strings.Split(this.Address, ":")
if len(hp) != 2 {
return fmt.Errorf("address format error")
}
arr := strings.Split(tos, ";")
count := len(arr)
safeArr := make([]string, 0, count)
for i := 0; i < count; i++ {
if arr[i] == "" {
continue
}
safeArr = append(safeArr, arr[i])
}
if len(safeArr) == 0 {
return fmt.Errorf("tos invalid")
}
tos = strings.Join(safeArr, ";")
b64 := base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
header := make(map[string]string)
header["From"] = from
header["To"] = tos
header["Subject"] = fmt.Sprintf("=?UTF-8?B?%s?=", b64.EncodeToString([]byte(subject)))
header["MIME-Version"] = "1.0"
ct := "text/plain; charset=UTF-8"
if len(contentType) > 0 && contentType[0] == "html" {
ct = "text/html; charset=UTF-8"
}
header["Content-Type"] = ct
header["Content-Transfer-Encoding"] = "base64"
message := ""
for k, v := range header {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + b64.EncodeToString([]byte(body))
auth := smtp.PlainAuth("", this.Username, this.Password, hp[0])
return smtp.SendMail(this.Address, auth, from, strings.Split(tos, ";"), []byte(message))
}
开发者ID:toolkits,项目名称:smtp,代码行数:51,代码来源:smtp.go
示例19: getAuthHeader
/**
* getAuthHeader generates a base64 encoded auth-header value
* which can be used in a http request to access restricted urls.
*/
func getAuthHeader(client *Client) string {
// base64 encode the username and password
var encoding = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
//log.Stdout(client.Username+":"+client.Password);
var src []byte = strings.Bytes(client.Username + ":" + client.Password)
var encodedLen int = encoding.EncodedLen(len(src))
var dest = make([]byte, encodedLen)
encoding.Encode(dest, src)
var destSlice = dest[0:encodedLen]
// convert bytes to string
var destStr = "Basic " + bytes.NewBuffer(destSlice).String()
return destStr
}
开发者ID:tommed,项目名称:GoogleGo-Twitter-Client,代码行数:18,代码来源:twitter.go
示例20: tNewEncoding
func tNewEncoding() {
base64Table := "123QRSTUabcdVWXYZHijKLAWDCABDstEFGuvwxyzGHIJklmnopqr234560178912"
// P(len(base64Table))
coder := base64.NewEncoding(base64Table)
output := coder.EncodeToString(input)
stoutput := base64.StdEncoding.EncodeToString(input)
P(output)
P(stoutput)
input2, _ := coder.DecodeString(output)
input2Std, _ := base64.StdEncoding.DecodeString(stoutput)
P(string(input2))
P(string(input2Std))
}
开发者ID:zykzhang,项目名称:practice,代码行数:15,代码来源:base64.go
注:本文中的encoding/base64.NewEncoding函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论