Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created April 23, 2013 14:51
Show Gist options
  • Save hnakamur/5444210 to your computer and use it in GitHub Desktop.
Save hnakamur/5444210 to your computer and use it in GitHub Desktop.
GoでHMAC SHA1を計算するサンプル
package sample
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"io"
"testing"
)
func TestHmacSha1(t *testing.T) {
key := ([]byte)("93f75ae483d03c23358fa5330ff4a3f5")
hash := hmac.New(sha1.New, key)
io.WriteString(hash, "foo bar")
result := base64.StdEncoding.EncodeToString(hash.Sum(nil))
if result != "vR6e4+MqTiWyuQN12YYrFerO5I4=" {
t.Fatalf("wrong HMAC SHA1 result: %s", result)
}
}
@hnakamur
Copy link
Author

参考: Cのサンプル
Openssl HMAC SHA1を試す http://kaworu.jpn.org/kaworu/2007-03-22-1.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment