当前位置: 首页>>代码示例>>Golang>>正文


Golang hmac.NewSHA1函数代码示例

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


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


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