• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang hmac.NewSHA1函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中crypto/hmac.NewSHA1函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSHA1函数的具体用法?Golang NewSHA1怎么用?Golang NewSHA1使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewSHA1函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: AuthenticateServer

func AuthenticateServer(conn net.Conn, secret []byte) os.Error {
	challenge := make([]byte, challengeLength)
	n, err := conn.Read(challenge)
	if err != nil {
		return err
	}
	challenge = challenge[:n]

	h := hmac.NewSHA1(secret)
	h.Write(challenge)
	_, err = conn.Write(h.Sum())
	if err != nil {
		return err
	}

	expectAck := []byte("OK")
	ack := make([]byte, len(expectAck))
	n, err = conn.Read(ack)
	if err != nil {
		return err
	}

	ack = ack[:n]
	if bytes.Compare(expectAck, ack) != 0 {
		fmt.Println(expectAck, ack)
		return os.NewError("Missing ack reply")
	}
	return nil
}
开发者ID:krasin,项目名称:termite,代码行数:29,代码来源:connection.go


示例2: HashString

func HashString(key []byte, hashThis string) string {
	// log.Println( "Hashing this string: ", hashThis )
	// log.Println( "SHA1 Key: ", key )
	sha1 := hmac.NewSHA1(key)
	sha1.Write([]byte(hashThis))
	return base64.StdEncoding.EncodeToString(sha1.Sum())
}
开发者ID:natelong,项目名称:playlistr,代码行数:7,代码来源:easyauth.go


示例3: GetSignature

// Calculates the HMAC-SHA1 signature of a base string, given a consumer and
// token secret.
func (s *HmacSha1Signer) GetSignature(consumerSecret string, tokenSecret string, signatureBase string) string {
	signingKey := consumerSecret + "&" + tokenSecret
	signer := hmac.NewSHA1([]byte(signingKey))
	signer.Write([]byte(signatureBase))
	oauthSignature := base64.StdEncoding.EncodeToString(signer.Sum())
	return oauthSignature
}
开发者ID:paul-lalonde,项目名称:golibs,代码行数:9,代码来源:oauth1a.go


示例4: genSig

func (y *Yubikey) genSig(params map[string]string) string {
	keys := make([]string, len(params))
	i := 0
	for k, _ := range params {
		keys[i] = k
		i++
	}
	sort.Strings(keys)

	buf := bytes.NewBuffer([]byte{})

	for i, key := range keys {
		buf.WriteString(key + "=" + params[key])
		if i != len(keys)-1 {
			buf.WriteString("&")
		}
	}

	h := hmac.NewSHA1(y.key)

	h.Write(buf.Bytes())

	rawSig := h.Sum()

	sig := make([]byte, base64.StdEncoding.EncodedLen(len(rawSig)))
	base64.StdEncoding.Encode(sig, rawSig)

	return string(sig)
}
开发者ID:jeffreybolle,项目名称:goyubikey,代码行数:29,代码来源:yubikey.go


示例5: setupKeys

// setupKeys sets the cipher and MAC keys from kex.K, kex.H and sessionId, as
// described in RFC 4253, section 6.4. direction should either be serverKeys
// (to setup server->client keys) or clientKeys (for client->server keys).
func (c *common) setupKeys(d direction, K, H, sessionId []byte, hashFunc crypto.Hash) error {
	cipherMode := cipherModes[c.cipherAlgo]

	macKeySize := 20

	iv := make([]byte, cipherMode.ivSize)
	key := make([]byte, cipherMode.keySize)
	macKey := make([]byte, macKeySize)

	h := hashFunc.New()
	generateKeyMaterial(iv, d.ivTag, K, H, sessionId, h)
	generateKeyMaterial(key, d.keyTag, K, H, sessionId, h)
	generateKeyMaterial(macKey, d.macKeyTag, K, H, sessionId, h)

	c.mac = truncatingMAC{12, hmac.NewSHA1(macKey)}

	cipher, err := cipherMode.createCipher(key, iv)
	if err != nil {
		return err
	}

	c.cipher = cipher

	return nil
}
开发者ID:davecheney,项目名称:ssh,代码行数:28,代码来源:transport.go


示例6: AuthenticateClient

func AuthenticateClient(conn net.Conn, secret []byte) os.Error {
	challenge := make([]byte, 0)
	for i := 0; i < challengeLength; i++ {
		challenge = append(challenge, byte(rand.Int31n(256)))
	}

	_, err := conn.Write(challenge)
	if err != nil {
		return err
	}

	h := hmac.NewSHA1(secret)
	_, err = h.Write(challenge)
	expected := h.Sum()
	response := make([]byte, len(expected))
	n, err := conn.Read(response)
	if err != nil {
		return err
	}
	response = response[:n]

	if bytes.Compare(response, expected) != 0 {
		log.Println("Authentication failure from", conn.RemoteAddr())
		return os.NewError("Mismatch in response")
	}
	conn.Write([]byte("OK"))
	return nil
}
开发者ID:krasin,项目名称:termite,代码行数:28,代码来源:connection.go


示例7: getCookieSig

func getCookieSig(key string, val []byte, timestamp string) string {
	hm := hmac.NewSHA1([]byte(key))

	hm.Write(val)

	hex := fmt.Sprintf("%02x", hm.Sum([]byte(timestamp)))
	return hex
}
开发者ID:TheOnly92,项目名称:web.go,代码行数:8,代码来源:web.go


示例8: getCookieSig

func getCookieSig(val []byte, timestamp string) string {
	hm := hmac.NewSHA1([]byte(serverSecret))
	hm.Write(val)
	hm.Write([]byte(timestamp))

	hex := fmt.Sprintf("%02x", hm.Sum())
	return hex
}
开发者ID:AaronO,项目名称:lightwave,代码行数:8,代码来源:server.go


示例9: Signature

// Returns the signature to be used in the query string or Authorization header
func Signature(secret, toSign string) string {
	// Signature = Base64( HMAC-SHA1( UTF-8-Encoding-Of( YourSecretAccessKeyID, StringToSign ) ) );
	// Need to confirm what encoding go strings are when converted to []byte
	hmac := hmac.NewSHA1([]byte(secret))
	hmac.Write([]byte(toSign))

	return base64.StdEncoding.EncodeToString(hmac.Sum())
}
开发者ID:streadway,项目名称:s3sig,代码行数:9,代码来源:sign.go


示例10: sign

// ----------------------------------------------------------------------------
// Mechanical Turk signing (http://goo.gl/wrzfn)
func sign(auth aws.Auth, service, method, timestamp string, params map[string]string) {
	payload := service + method + timestamp
	hash := hmac.NewSHA1([]byte(auth.SecretKey))
	hash.Write([]byte(payload))
	signature := make([]byte, b64.EncodedLen(hash.Size()))
	b64.Encode(signature, hash.Sum())

	params["Signature"] = string(signature)
}
开发者ID:laslowh,项目名称:mturk,代码行数:11,代码来源:sign.go


示例11: signature

func signature(secret, key, expiration, value string) string {
	hm := hmac.NewSHA1([]byte(secret))
	io.WriteString(hm, key)
	hm.Write([]byte{0})
	io.WriteString(hm, expiration)
	hm.Write([]byte{0})
	io.WriteString(hm, value)
	return hex.EncodeToString(hm.Sum())
}
开发者ID:chillicoder,项目名称:twister,代码行数:9,代码来源:misc.go


示例12: Digest

func Digest(key string, m string) string {
	myhash := hmac.NewSHA1(strings.Bytes(key));
	myhash.Write(strings.Bytes(m));
	signature := bytes.TrimSpace(myhash.Sum());
	digest := make([]byte, base64.StdEncoding.EncodedLen(len(signature)));
	base64.StdEncoding.Encode(digest, signature);
	digest_str := strings.TrimSpace(bytes.NewBuffer(digest).String());
	return digest_str;
}
开发者ID:montsamu,项目名称:go-twitter-oauth,代码行数:9,代码来源:oauth.go


示例13: createSessionId

func createSessionId(username string) string {
	hm := hmac.NewSHA1([]byte(ServerSecret))
	hm.Write([]byte(username))
	hm.Write([]byte(strconv.Itoa64(sessionIdCounter)))
	hm.Write([]byte(strconv.Itoa64(time.Seconds())))
	sessionIdCounter++
	hex := fmt.Sprintf("%02x", hm.Sum())
	return hex
}
开发者ID:AaronO,项目名称:lightwave,代码行数:9,代码来源:session.go


示例14: macSHA1

// macSHA1 returns a macFunction for the given protocol version.
func macSHA1(version uint16, key []byte) macFunction {
	if version == versionSSL30 {
		mac := ssl30MAC{
			h:   sha1.New(),
			key: make([]byte, len(key)),
		}
		copy(mac.key, key)
		return mac
	}
	return tls10MAC{hmac.NewSHA1(key)}
}
开发者ID:Quantumboost,项目名称:gcc,代码行数:12,代码来源:cipher_suites.go


示例15: Sign

func (s *SHA1Signer) Sign(message string, key string) string {
	if s.debug {
		fmt.Println("Signing:" + message)
		fmt.Println("Key:" + key)
	}
	hashfun := hmac.NewSHA1([]byte(key))
	hashfun.Write([]byte(message))
	rawsignature := hashfun.Sum()
	base64signature := make([]byte, base64.StdEncoding.EncodedLen(len(rawsignature)))
	base64.StdEncoding.Encode(base64signature, rawsignature)
	return string(base64signature)
}
开发者ID:newblue,项目名称:oauth,代码行数:12,代码来源:oauth.go


示例16: sign

func sign(key string, str string, method string) ([]byte, os.Error) {
	var hash hash.Hash

	if method == "HMAC-SHA1" {
		hash = hmac.NewSHA1([]byte(key))
	} else {
		return nil, os.NewError(fmt.Sprintf("Unsupported signature method: %s", method))
	}

	hash.Write([]byte(str))

	return hash.Sum(), nil
}
开发者ID:hpcorona,项目名称:goa1,代码行数:13,代码来源:goa1.go


示例17: digest

// digest Generates a HMAC-1234 for the signature
func (oc *OAuthConsumer) digest(key string, m string) string {
	h := hmac.NewSHA1([]byte(key))
	h.Write([]byte(m))
	return base64encode(h.Sum())

	/*	s := bytes.TrimSpace(h.Sum())
		d := make([]byte, base64.StdEncoding.EncodedLen(len(s)))
		base64.StdEncoding.Encode(d, s)
		ds := strings.TrimSpace(bytes.NewBuffer(d).String())
	*/
	//	return ds

}
开发者ID:kai-zoa,项目名称:goauth,代码行数:14,代码来源:oauthconsumer.go


示例18: sign

func sign(conn net.Conn, challenge []byte, secret []byte, local bool) []byte {
	h := hmac.NewSHA1(secret)
	h.Write(challenge)
	l := conn.LocalAddr()
	r := conn.RemoteAddr()
	connSignature := ""
	if local {
		connSignature = fmt.Sprintf("%v-%v", l, r)
	} else {
		connSignature = fmt.Sprintf("%v-%v", r, l)
	}
	h.Write([]byte(connSignature))
	return h.Sum()
}
开发者ID:lht,项目名称:termite,代码行数:14,代码来源:connection.go


示例19: signRequest

func signRequest(base string, consumerSecret string, tokenSecret string) string {
	signingKey := URLEscape(consumerSecret) + "&"
	if tokenSecret != "" {
		signingKey += URLEscape(tokenSecret)
	}
	hash := hmac.NewSHA1([]byte(signingKey))
	hash.Write([]byte(base))
	sum := hash.Sum()
	bb := new(bytes.Buffer)
	encoder := base64.NewEncoder(base64.StdEncoding, bb)
	encoder.Write(sum)
	encoder.Close()
	return bb.String()
}
开发者ID:gmarik,项目名称:twitterstream,代码行数:14,代码来源:oauth.go


示例20: signHandler

// Signs the Content
func signHandler(w http.ResponseWriter, r *http.Request) {
	dec := json.NewDecoder(r.Body)
	var data Signature
	dec.Decode(&data)
	keyBytes := []byte(data.Key)
	content := data.Content
	mac := hmac.NewSHA1(keyBytes)
	mac.Write([]byte(content))

	out := make([]byte, base64.StdEncoding.EncodedLen(len(mac.Sum())))
	base64.StdEncoding.Encode(out, mac.Sum())

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(&Signature{string(out), content, data.Key})
}
开发者ID:paulosuzart,项目名称:gosigner,代码行数:16,代码来源:gosigner.go



注:本文中的crypto/hmac.NewSHA1函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang hmac.Sum函数代码示例发布时间:2022-05-24
下一篇:
Golang hmac.New函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap