Code Monkey home page Code Monkey logo

ecdsa's Introduction

ECDSA in Go

ECDSA implementation in Go. Task โ„–8 for the Cryptography for Developers course.

Setup

Execute the following command first:

go get github.com/danielost/ecdsa

Then simply add the following import to your Go code:

import (
  // Importing the ECDSA package
  "github.com/danielost/ecdsa/internal/ecdsa"
)

API description

ECDSA:

  • GenerateKeys() (*KeyPair, error) - Generates a new ECDSA key pair
  • Sign(message []byte, privateKey *big.Int) (*Signature, error) - Signs a message using the private key
  • Verify(message []byte, publicKey *ecwrapper.ECPoint, sig *Signature) bool - Verifies a message using the public key

Convenience methods:

  • SerializePublicKey(publicKey *ecwrapper.ECPoint, base int) string - Serializes a public key
  • DeserializePublicKey(publicKey string, base int) (*ecwrapper.ECPoint, error) - Deserializes a public key
  • SerializePrivateKey(privateKey *big.Int, base int) string - Serializes a private key
  • DeserializePrivateKey(privateKey string, base int) (*big.Int, error) - Deserializes a private key
  • SerializeSignature(signature *Signature, base int) string - Serializes a signature
  • DeserializeSignature(signature string, base int) (*Signature, error) - Deserializes a signature

Examples

Examples folder contains guides on how to generate keys and sign and verify messages.

Example of signing a message:

package main

import (
	"fmt"
	"log"

	"github.com/danielost/ecdsa/internal/ecdsa"
)

func main() {
	// You can either generate a key pair or use previously generated keys.
	// See how to generate a key pair in ./examples/keygen/keygen.go.
	// Most likely, you will have your keys stored as strings. Use deserialization methods to convert them
	// to the required objects.
	base := 16
	sPrivateKey := "bb072d57567f800e4d0a00a0eba95e9f33b839b3b18728fc3000dfb2e4d9621d"
	// sPublicKey := "3fb8197d8566fde03a1b7df6ea4af1b6696f08b5d0416fa5fa82cbcdddeaad93:6a53606718d9971c9a1a264dd951617e7c3e4d8af8ab19a7d5944425c2904ab7"
	privateKey, err := ecdsa.DeserializePrivateKey(sPrivateKey, base)
	if err != nil {
		log.Fatal(err)
	}

	message := "Send $100 to Bob now!"
	signature, err := ecdsa.Sign([]byte(message), privateKey)
	if err != nil {
		log.Fatal(err)
	}

	// You can now serialize the signature along with the public key and save or send them
	sSignature := ecdsa.SerializeSignature(signature, base)

	fmt.Println(sSignature)
}

Testing

To run the tests, clone the repository and execute the following command:

go test ./...

or (for the detailed view):

go test -v ./...

ecdsa's People

Contributors

danielost avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.