ecdsa-digital-signature example
To verify who a message is from,
create and verify a digital signature using the
crypto/ecdsa
standard package.
Refer to the
crypto/ecdsa
package for more info.
GitHub Webpage
OVERVIEW
Digital signatures are based on elliptic curve cryptography (ECC) and
are important for message validation.
The Elliptic Curve Digital Signature Algorithm
is a great way to cryptographically sign a message.
This illustration may help,
RUN
go run ecdsa-digital-signature.go <FILENAME>
go run ecdsa-digital-signature.go test.txt
HOW IT WORKS
Generate ecdsa keys,
// GENERATE PRIVATE & PUBLIC KEY PAIR
curve := elliptic.P256()
privateKeyRaw, err := ecdsa.GenerateKey(curve, rand.Reader)
// EXTRACT PUBLIC KEY
publicKeyRaw := &privateKeyRaw.PublicKey
Create a digital signature,
// CREATE SIGNATURE
r, s, err := ecdsa.Sign(rand.Reader, senderPrivateKeyRaw, signHash)
signatureByte := r.Bytes()
signatureByte = append(signatureByte, s.Bytes()...)
Verify the digital signature,
// VERIFY SIGNATURE
verifyStatus := ecdsa.Verify(senderPublicKeyRaw, signhash, r, s)