Photo by Signature Pro on Unsplash

Can We Recover The Public Key from an ECDSA Signature?

--

With ECDSA we create a signature with a private key and then prove with a public key. A special feature of ECDSA is that we can recover the public key from the signature.

With ECDSA we have a signature value of (r,s,v) and we can use these values to recover the public key. In the following, we see an Ethereum transaction, and where the r, s, and v values are stored with the transaction:

In this case, we will create a random private key, and then derive the public key. Next, we will generate an ECDSA signature for a given data value, and then recover the public key using two methods (SigToPub and Ecrecover) from github.com/ethereum/go-ethereum/crypto.

The following code is used to create a SHA-3 hash from the data, and then sign with the private key:

hash := crypto.Keccak256Hash(data)
fmt.Printf("Hash: %x\n", hash.Bytes())

--

--

Prof Bill Buchanan OBE FRSE
ASecuritySite: When Bob Met Alice

Professor of Cryptography. Serial innovator. Believer in fairness, justice & freedom. Based in Edinburgh. Old World Breaker. New World Creator. Building trust.