package main

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

func main() {
res := SHA256("jdlsjfkjhfj123232")
fmt.Println(res) // c40bad10eca3f4e355b313abfe44dd20ec4bdbc30d6c7f932c74f1ddbcbadab5

res1 := HmacSHA256("abcd", "123456") // YTY1MDE0YzBkZmE1Nzc1MWE3NDk4NjZlODQ0YjZjNDIyNjZiOWI3ZDU0ZDVjNTlmN2Y3MDY3ZDk3M2Y3NzgxNw==
fmt.Println(res1)
}

func SHA256(str string) string{
ctx := sha256.New()
ctx.Write([]byte(str))
return hex.EncodeToString(ctx.Sum(nil))
}

func HmacSHA256(str string, secret string) string{
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(str))
sha := hex.EncodeToString(h.Sum(nil))
fmt.Println(sha)
return base64.StdEncoding.EncodeToString([]byte(sha))
}