Created
April 23, 2013 14:51
-
-
Save hnakamur/5444210 to your computer and use it in GitHub Desktop.
GoでHMAC SHA1を計算するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考: Cのサンプル
Openssl HMAC SHA1を試す http://kaworu.jpn.org/kaworu/2007-03-22-1.php