Golangはsha 256暗号化を実現

1367 ワード

まずPHPコードを貼り付けます.
$string = "1234";
$key = "abcd";
$signature = hash_hmac('sha256', $string, $key);
そしてGolang:
package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"fmt"
)

func main() {
	s := []byte("1234")
	key := []byte("abcd")
	m := hmac.New(sha256.New, key )
	m.Write( s )
	signature := hex.EncodeToString(m.Sum(nil))
	fmt.Print(signature + "
\r") }
署名は、d 219 a 3 dd 877 f 943 be 0 ee 65 ef 6 a 34129778 d 2 fd 0568 ce 2 d 9 a 8 f 37 fea 9 d 7 fcacac 3