I have used the following code to generate an ecdsa key-pair(privKey
and pubKey
), encode them and then decode them back: https://stackoverflow.com/a/41315404/1901320.
Next I create a hash for a message (txnData.Payload()
is of type []byte
) using crypto.Keccak256()
and sign it using crypto.Sign()
from Ethereum's crypto package (github.com/ethereum/go-ethereum/crypto
). This creates a 65 bit ECDSA signature in R || S || V format.
hashData := crypto.Keccak256(txnData.Payload)
sig, _ := crypto.Sign(hashData, privKey)
pkey, _ := crypto.Ecrecover(hashData, sig) // This and pubKey do not match
When I try to get back the public key from the hashData
and the ECDSA signature using crypto.Ecrecover()
and compare it with the public key pubKey
corresponding to the privKey
used to create the signature, I find that the public keys do not match. This doesn't seem like something that should happen. Any idea as to where I am going wrong with this?