package main import ( "crypto/rand" "crypto/rsa" "crypto/sha256" "crypto/x509" "encoding/base64" "encoding/pem" "errors" "fmt" ) func decodeMessage(ciphertext []byte, stringKey string) ([]byte, error) { block, _ := pem.Decode([]byte(stringKey)) if block == nil { return nil, errors.New("key is not found in given string") } key, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { return nil, err } plaintext, err := rsa.DecryptPKCS1v15(rand.Reader, key, ciphertext) if err != nil { return nil, err } return plaintext, err } func checkSignature(payload string, signature string, key string) (bool, error) { h := sha256.Sum256([]byte(payload)) requestHash := fmt.Sprintf("%x", h) decodedSign, err := base64.StdEncoding.DecodeString(signature) if err != nil { return false, err } signHash, err := decodeMessage(decodedSign, key) if err != nil { return false, err } return requestHash == string(signHash), nil }