ecc

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2020 License: MIT Imports: 10 Imported by: 0

README

Compatible with swift library https://github.com/IBM-Swift/BlueECC

Example usage

package main

import (
	"fmt"
	"github.com/itrabbit/ecc"
)

func main()  {
        private, err := ecc.GenerateKey()
        if err != nil {
            panic(err.Error())
        }

        encrypted, err := ecc.Encrypt(&private.PublicKey, []byte("hello"))
        if err != nil {
            panic(err.Error())
        }

        fmt.Println("encrypted", encrypted, len(encrypted));
        // -> encrypted [4 13 13 236 218 227 ... 89] 86

        decrypted, err := ecc.Decrypt(private, encrypted)
        if err != nil {
            panic(err.Error())
        }

        fmt.Println("decrypted", decrypted, string(decrypted))
        // -> decrypted [104 101 108 108 111] hello
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key crypto.PrivateKey, data []byte) (decrypted []byte, err error)

func Encrypt

func Encrypt(key crypto.PublicKey, data []byte) (encrypted []byte, err error)

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	D []byte
}

func GenerateKey

func GenerateKey() (*PrivateKey, error)

func KeyFromString

func KeyFromString(private string) (*PrivateKey, error)

func (PrivateKey) String

func (key PrivateKey) String() string

type PublicKey

type PublicKey struct {
	elliptic.Curve
	X, Y *big.Int
}

func PublicKeyFromString

func PublicKeyFromString(public string) (*PublicKey, error)

func (PublicKey) String

func (key PublicKey) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL