Пример #1
0
// 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
0
// 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
0
// 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
0
// 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
0
// 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
0
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
0
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
0
// 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
0
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
0
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
0
func Base64Encode(enc *base64.Encoding, src []byte) []byte {
	l := len(src)
	dst := make([]byte, enc.EncodedLen(l))
	enc.Encode(dst, src)
	return dst
}
Пример #12
0
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
}