SM2国密之Go语言实现数字签名与验证

package main

import (
	"github.com/tjfoc/gmsm/sm2"
	"fmt"
	"crypto/sha256"
)

func handleErr(e error,why string){
	if e!=nil{
		fmt.Println(why,e)
	}
}

func main() {

	privateKey, e := sm2.GenerateKey()
	handleErr(e,"get priv key error ")

	publicKey := privateKey.PublicKey
	hash := sha256.Sum256([]byte("wek"))
	r, s, err := sm2.Sign(privateKey, hash[:])
	handleErr(err,"sign" )
	verify := sm2.Verify(&publicKey, hash[:], r, s)
	fmt.Println(verify)

}

 

结果为:

SM2国密之Go语言实现数字签名与验证_第1张图片

你可能感兴趣的:(密码学)