lazyxchacha

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 5 Imported by: 1

README

lazyxchacha

Lazy XChaCha20-Poly1305 in golang.

Go Report Card

Install
go get github.com/prongbang/lazyxchacha
Benchmark
BenchmarkEncrypt-10    	 1220955	       984.5 ns/op	     944 B/op	       5 allocs/op
BenchmarkDecrypt-10    	 1706475	       695.0 ns/op	     576 B/op	       4 allocs/op
How to use
  • Generate KeyPair
keyPair := lazyxchacha.NewKeyPair()
  • Key Exchange
// Generate KeyPair
clientKp := lazyxchacha.NewKeyPair()
serverKp := lazyxchacha.NewKeyPair()

serverKx := serverKp.Exchange(clientKp.Pk)
clientKx := clientKp.Exchange(serverKp.Pk)
  • Shared Key
serverSharedKey, _ := serverKx.Secret()
clientSharedKey, _ := clientKx.Secret()
  • Encrypt
lazyXchacha := lazyxchacha.New()
key, _ := lazyXchacha.RandomKey()
plaintext := "text"
ciphertext, err := lazyXchacha.Encrypt(plaintext, key)
  • Decrypt
lazyXchacha := lazyxchacha.New()
key := "e7de22e8"
ciphertext := "f6a1bd8"
plaintext, err := lazyXchacha.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 LazyXChaCha

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

func New

func New() LazyXChaCha

Jump to

Keyboard shortcuts

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