Skip to content

denkochev/ECDSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ECDSA signature with SHA256 on secp256k1

Naive implementation of ECDSA signature algorithm on secp256k1 elliptic curve with sha256 hash function.

Installation

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

Usage

Package includes two structures: for publicKey (ElipticPoint) and for signature (Signature).

How to sign message:

  1. Generate key pair using ecdsa.KeyGen() func.
privateKey, publicKey := ecdsa.KeyGen()
  1. 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.

How to verify signature

  1. 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.

Parsers

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)

Releases

No releases published

Packages

No packages published

Languages