diffiehellman

package module
v0.0.0-...-5519a41 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 2 Imported by: 0

README

image description

go version license version

Diffie-Hellman

Diffie-Hellman is a lightweight package that provides an implementation of diffie-hellman algorithm in Go. for seeing usages check this.

The Diffie-Hellman is a key-exchange protocol that enables two parties communicating over a public channel to establish a mutual secret without transmitting it over the internet. It allows the two parties to use a public key to encrypt and decrypt their conversation or data using symmetric cryptography.

It is widely used in protocols such as Secure Shell (SSH), Internet Protocol Security (IPSec), and Public Key Infrastructure (PKI) to facilitate secure key exchange and enhance data confidentiality over public networks.

Documentation

Install

go get github.com/erfanmomeniii/diffiehellman

Next, include it in your application:

import "github.com/erfanmomeniii/diffiehellman"

Quick Start

The following example demonstrates how to use this package for generating the same transport key:

package main

import (
	"fmt"

	"github.com/erfanmomeniii/diffiehellman"
)

func main() {
	clientA, _ := diffiehellman.New(10141)
	clientB, _ := diffiehellman.New(10141)
	// The parameter should be a prime number.

	fmt.Println(clientA.GetPrivateKey(), clientA.GetPublicKey())
	// 4294 5299
	fmt.Println(clientB.GetPrivateKey(), clientB.GetPublicKey())
	// 2560 3789
	fmt.Println(clientA.GenerateTransportKey(clientB.GetPublicKey()))
	// 6933
	fmt.Println(clientB.GenerateTransportKey(clientA.GetPublicKey()))
	// 6933
}

Contributing

Pull requests are welcome. For changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffieHellman

type DiffieHellman struct {
	// contains filtered or unexported fields
}

func New

func New(primeNumber ...int64) (*DiffieHellman, error)

func (*DiffieHellman) GenerateTransportKey

func (dh *DiffieHellman) GenerateTransportKey(publicKey int64) int64

func (*DiffieHellman) GetPrivateKey

func (dh *DiffieHellman) GetPrivateKey() int64

func (*DiffieHellman) GetPublicKey

func (dh *DiffieHellman) GetPublicKey() int64

func (*DiffieHellman) SetPrimeNumber

func (dh *DiffieHellman) SetPrimeNumber(primeNumber int64) error

Jump to

Keyboard shortcuts

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