Help us shape the future of Go! Take the 2026 Go Developer Survey

eciesbls12381

package module
v0.0.0-...-3b0cbc1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 7 Imported by: 0

README

Package ecies-bls12381

GoDoc codecov Go Report Card

ecies-bls12381 is a Go package that simplifies keypair generation, encryption, and decryption using Elliptic Curve Integrated Encryption Scheme (ECIES) with the BLS12381 elliptic curve. It leverages the Kyber cryptographic library for secure operations, making it easy for developers to integrate robust cryptographic functionalities into their applications. Suitable for proxy re-encryption.

This package is built on top of the github.com/drand/kyber library, which provides a high-level API for cryptographic operations. The BLS12381 elliptic curve is a pairing-friendly curve that is widely used in cryptographic applications, including proxy re-encryption and secure data sharing.

Key Features

  • Key Pair Generation: Generate secure elliptic curve key pairs.
  • Public Key Derivation: Derive public keys from private keys.
  • Message Encryption: Encrypt messages securely using public keys.
  • Message Decryption: Decrypt messages using corresponding private keys.
  • Proxy Re-Encryption Support: Suitable for use cases involving proxy re-encryption for secure data sharing.

Installation

To install the package, run:

go get github.com/rafagomes/ecies-bls12381

Usage

package main

import (
	"fmt"

	eciesbls12381 "github.com/rafagomes/ecies-bls12381"
)

func main() {
	// Generate key pair
	publicKey, privateKey := eciesbls12381.GenerateECKeypair()
	fmt.Println("Public Key:", publicKey)
	fmt.Println("Private Key:", privateKey)

	// Encrypt a message
	message := []byte("Hello, BLS12381!")
	ciphertext, err := eciesbls12381.EncryptWithEC(publicKey, message)
	if err != nil {
		fmt.Println("Encryption error:", err)
		return
	}
	fmt.Println("Ciphertext:", ciphertext)

	// Decrypt the message
	plaintext, err := eciesbls12381.DecryptWithEC(privateKey, ciphertext)
	if err != nil {
		fmt.Println("Decryption error:", err)
		return
	}
	fmt.Println("Plaintext:", string(plaintext))
}
Code Examples
Basic Encryption and Decryption

You can find the example code for basic encryption and decryption in the examples/basic-encryption.

Proxy Re-Encryption

You can find the example code for proxy re-encryption in the examples/proxy-reencryption.

Contributing

Feel free to open issues and pull requests. Any feedback is highly appreciated!

Authors

@rafagomes

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptWithEC

func DecryptWithEC(privateKey kyber.Scalar, ciphertext []byte) ([]byte, error)

DecryptWithEC decrypts a ciphertext using the recipient's private key.

func EncryptWithEC

func EncryptWithEC(publicKey kyber.Point, message []byte) ([]byte, error)

EncryptWithEC encrypts a message using the recipient's public key.

func GenerateECKeypair

func GenerateECKeypair() (kyber.Point, kyber.Scalar)

GenerateECKeypair generates a new elliptic curve key pair.

func GenerateECPrivateKey

func GenerateECPrivateKey() kyber.Scalar

GenerateECPrivateKey generates a new elliptic curve private key.

func GetECPublicKeyFromPrivateKey

func GetECPublicKeyFromPrivateKey(privateKey kyber.Scalar) (kyber.Point, error)

GetECPublicKeyFromPrivateKey derives the public key from a given private key.

Types

type ECPoint

type ECPoint struct {
	X, Y *big.Int
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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