lazyxsalsa

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 5 Imported by: 0

README

lazyxsalsa

End-to-End Encryption an wrapper for libsodium in golang.

Go Report Card

Algorithm details
  • Key exchange: X25519
  • Encryption: XSalsa20
  • Authentication: Poly1305
Install
go get github.com/prongbang/lazyxsalsa
Benchmark
BenchmarkEncrypt-10        35792             33285 ns/op
BenchmarkDecrypt-10        36526             32821 ns/op
How to use
  • Create KeyPair
keyPair := lazyxsalsa.NewKeyPair()
  • Key Exchange
clientKp := lazyxsalsa.NewKeyPair()
serverKp := lazyxsalsa.NewKeyPair()
clientSharedKey := clientKp.Exchange(serverKp.Pk)
serverSharedKey := serverKp.Exchange(clientKp.Pk)
  • Encrypt
lazyXsalsa := lazyxsalsa.New()

plaintext := `Plaintext`
ciphertext, err := lazyXsalsa.Encrypt(plaintext, clientSharedKey)
  • Decrypt
lazyXsalsa := lazyxsalsa.New()

ciphertext := "ae76477791140129a083a09ff68d5b10460f125c9affdefff48d52d30d774a7c3f42f364ea581eb9b114a65cdbf535171a"
plaintext, err := lazyXsalsa.Decrypt(ciphertext, serverSharedKey)

Documentation

Index

Constants

View Source
const NonceHexSize = 24 * 2

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 ToKeyPair

func ToKeyPair(kpStr string) KeyPair

ToKeyPair kpStr is KeyPair json format

func (KeyPair) Exchange

func (k KeyPair) Exchange(pk string) KeyPair

Exchange pk is client Public Key

func (KeyPair) ToString

func (k KeyPair) ToString() string

ToString return KeyPair json format

type LazyXSalsa

type LazyXSalsa interface {
	Encrypt(plainText string, keyPair KeyPair) (string, error)
	Decrypt(cipherText string, keyPair KeyPair) (string, error)
}

func New

func New() LazyXSalsa

Jump to

Keyboard shortcuts

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