Skip to content

prongbang/lazyaesgcm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lazyaesgcm

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

Go Report Card

"Buy Me A Coffee"

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)