lazyaesgcm

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 6 Imported by: 0

README

lazyaesgcm

Lazy AES-GCM in golang on golang.org/x/crypto.

Go Report Card

Algorithm details
  • Key exchange: X25519
  • Encryption: AES
  • Authentication: GCM
Install
go get github.com/prongbang/lazyaesgcm
Benchmark
BenchmarkEncrypt-10    	  876500	      1352 ns/op	    1728 B/op	       9 allocs/op
BenchmarkDecrypt-10    	 1317686	       865.9 ns/op	    1408 B/op	       8 allocs/op
How to use
  • Generate KeyPair
keyPair := lazyaesgcm.NewKeyPair()
  • Key Exchange
clientKp := lazyaesgcm.NewKeyPair()
serverKp := lazyaesgcm.NewKeyPair()

serverKx := serverKp.Exchange(clientKp.Pk)
clientKx := clientKp.Exchange(serverKp.Pk)
  • Shared Key
serverSharedKey, _ := serverKx.Secret()
clientSharedKey, _ := clientKx.Secret()
  • Encrypt
lazyAesGcm := lazyaesgcm.New()
sharedKey, _ := clientKx.Secret()
key, _ := hex.DecodeString(sharedKey)
plaintext := "text"
ciphertext, err := lazyAesGcm.Encrypt(plaintext, key)
  • Decrypt
lazyAesGcm := lazyaesgcm.New()
sharedKey, _ := serverKx.Secret()
key, _ := hex.DecodeString(sharedKey)
ciphertext := "f6a1bd8"
plaintext, err := lazyAesGcm.Decrypt(ciphertext, key)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KeyPair

type KeyPair struct {
	Pk string `json:"pk"`
	Sk string `json:"sk"`
}

func NewKeyPair

func NewKeyPair() KeyPair

func (KeyPair) Exchange

func (k KeyPair) Exchange(pk string) KeyPair

func (KeyPair) Secret

func (k KeyPair) Secret() (string, error)

type LazyAesGcm

type LazyAesGcm interface {
	Encrypt(plaintext string, key []byte) (string, error)
	Decrypt(ciphertext string, key []byte) (string, error)
}

func New

func New() LazyAesGcm

Jump to

Keyboard shortcuts

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