Naive implementation of ECDSA signature algorithm on secp256k1 elliptic curve with sha256 hash function.
To use this wrapper you have to install bitcoin GO
implementation blockchain from: https://github.com/btcsuite/btcd/tree/master/btcec and secp256k1/v4 dir.
Use this command if your local environment doesn't have the required packages.
go get github.com/btcsuite/btcd@master
go get github.com/decred/dcrd/dcrec/secp256k1/v4
Package includes two structures: for publicKey (ElipticPoint) and for signature (Signature).
- Generate key pair using ecdsa.KeyGen() func.
privateKey, publicKey := ecdsa.KeyGen()
- Call function ecdsa.SIG.
You can sign any []byte includes your PC files. Let's sign text message.
message := "I'm a Fullstack developer *_*"
sig := ecdsa.SIG([]byte(message), privateKey)
SIG returns Signature
object with r and s as BigInts.
- To verify signature you have to know message itself, public key and signature.
ecdsa.Verify([]byte(message), publicKey, sig)
This function returns boolean value, true if signature valid, false in any other situations.
You can treat yours public key and signature as hex string.
hexSignature := sig.ToHex()
pkHex := publicKey.ToHex()
To use them in sign/ver algos you have to set objects from hex.
// for sig
newSignature := ecdsa.Signature{}
newSignature.SetFromHex(hexSignature)
// for pk
pkFromHex := ecdsa.ElipticPoint{}
pkFromHex.SetFromHex(pkHex)