本文整理匯總了Golang中encoding/base64.Encoding類的典型用法代碼示例。如果您正苦於以下問題:Golang Encoding類的具體用法?Golang Encoding怎麽用?Golang Encoding使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Encoding類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SignEncoded
// SignBytes, but will base64 encode based on the specified encoder.
func (self *Signer) SignEncoded(h crypto.Hash, s string, e *base64.Encoding) (out []byte, err error) {
ob, err := self.SignBytes(h, bytes.NewBufferString(s).Bytes())
if err == nil {
out = make([]byte, e.EncodedLen(len(ob)))
e.Encode(out, ob)
}
return
}
示例2: Encode
// Encode makes it a bit easier to deal with base 64 encoding, see
// example code below.
func Encode(encBuf, bin []byte, e64 *base64.Encoding) []byte {
maxEncLen := e64.EncodedLen(len(bin))
if encBuf == nil || len(encBuf) < maxEncLen {
encBuf = make([]byte, maxEncLen)
}
e64.Encode(encBuf, bin)
return encBuf[0:]
}
示例3: SignEncoded
// SignBytes, but will base64 encode based on the specified encoder.
func (p *signer) SignEncoded(h crypto.Hash, s string, enc *base64.Encoding) (signature []byte, err os.Error) {
buf, err := p.SignBytes(h, bytes.NewBufferString(s).Bytes())
if err == nil {
signature = make([]byte, enc.EncodedLen(len(buf)))
enc.Encode(signature, buf)
}
return
}
示例4: Sign64
// Sign a string with a specified signer and base64 encoding
func Sign64(s Signer, e *base64.Encoding, sts []byte) (out []byte, err os.Error) {
sig, err := s.Sign(sts)
if err != nil {
return
}
out = make([]byte, e.EncodedLen(len(sig)))
e.Encode(out, sig)
return
}
示例5: Decode
// Decode makes it a bit easier to deal with base 64 decoding, see
// example code below.
func Decode(decBuf, enc []byte, e64 *base64.Encoding) []byte {
maxDecLen := e64.DecodedLen(len(enc))
if decBuf == nil || len(decBuf) < maxDecLen {
decBuf = make([]byte, maxDecLen)
}
n, err := e64.Decode(decBuf, enc)
_ = err
return decBuf[0:n]
}
示例6: Sign64Mech
func Sign64Mech(mech string, s SignerMultiMech, e *base64.Encoding, sts []byte) (out []byte, err os.Error) {
sig, err := s.Sign(mech, sts)
if err != nil {
return
}
out = make([]byte, e.EncodedLen(len(sig)))
e.Encode(out, sig)
return
}
示例7: Base64Decode
func Base64Decode(enc *base64.Encoding, src []byte) ([]byte, error) {
l := len(src)
dst := make([]byte, enc.DecodedLen(l))
l, err := enc.Decode(dst, src)
if err != nil {
return nil, err
}
return dst[:l], nil
}
示例8: Sign64
// Sign a string with a specified signer and base64 encoding
func Sign64(s Signer, e *base64.Encoding,
ss Signable) (out []byte, err os.Error) {
sig, err := s.Sign(ss)
if err != nil {
return
}
bb := sig.SignatureBytes()
out = make([]byte, e.EncodedLen(len(bb)))
e.Encode(out, bb)
return
}
示例9: dns
func dns(username string, password string, domain string, ip string) string {
//base64
Authorization := username + ":" + password
encodeStd := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
var en *base64.Encoding = base64.NewEncoding(encodeStd)
var buf *bytes.Buffer = bytes.NewBufferString(Authorization)
enS := en.EncodeToString(buf.Bytes())
//http request and header
url := fmt.Sprintf("http://ddns.oray.com/ph/update?hostname=%s&myip=%s", domain, ip)
requ, _ := http.NewRequest("GET", url, nil)
requ.Header.Add("Authorization", "Basic "+enS)
requ.Header.Add("User-Agent", "FUCKALL")
client := new(http.Client)
resp, _ := client.Do(requ)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
buf = bytes.NewBuffer(body)
bufS := buf.String()
return bufS
}
示例10: search
func (s *Base64Finder) search(searchFor []byte, url bool) bool {
var encoding *base64.Encoding
if url {
encoding = base64.URLEncoding
} else {
encoding = base64.StdEncoding
}
i := 0
for i >= 0 {
var msg string
msg, i = s.findOne(i)
if len(msg) > 0 {
buf, err := encoding.DecodeString(msg)
if err == nil && FastByteArrayEq(searchFor, buf) {
return true
}
}
}
return false
}
示例11: Base64Encode
func Base64Encode(enc *base64.Encoding, src []byte) []byte {
l := len(src)
dst := make([]byte, enc.EncodedLen(l))
enc.Encode(dst, src)
return dst
}
示例12: SendMail
func (this *Sender) SendMail() (e error) {
var (
deadline time.Duration = 5 * time.Second
encoding *base64.Encoding
buf []byte = make([]byte, 512)
r int
)
encoding = base64.NewEncoding(tb)
conn, e := net.Dial("tcp", this.Host)
if e != nil {
return
}
defer conn.Close()
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte("EHLO Juxuny\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte("AUTH LOGIN\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte(encoding.EncodeToString([]byte(this.UserName)) + "\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte(encoding.EncodeToString([]byte(this.Password)) + "\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte("MAIL FROM: <" + this.From + ">" + "\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte("RCPT TO <" + this.To + ">\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
return
}
fmt.Println(string(buf[:r-1]))
conn.Write([]byte("DATA\r\n"))
conn.Write([]byte("\r\n"))
conn.Write([]byte("Message-ID: <" + this.From + ">\r\n"))
conn.Write([]byte("X-Mailer: <MMail 1.0>"))
conn.Write([]byte("MIME-Version: 1.0"))
conn.Write([]byte("Content-Type: text/plain"))
conn.Write([]byte("From: <" + this.From + ">\r\n"))
conn.Write([]byte("To: <" + this.To + ">\r\n"))
conn.Write([]byte("Subject: " + this.Subject + "\r\n"))
conn.Write([]byte("\r\n"))
conn.Write([]byte(this.Text))
conn.Write([]byte("\r\n.\r\n"))
time.Sleep(5e9)
conn.Write([]byte("QUIT\r\n"))
conn.SetDeadline(time.Now().Add(deadline))
r, e = conn.Read(buf)
if e != nil {
fmt.Println(e)
return
}
fmt.Println(string(buf[:r-1]))
return
}