Lazy XChaCha20-Poly1305 in golang base on golang.org/x/crypto.
- Key exchange: X25519
- Encryption: XChaCha20
- Authentication: Poly1305
go get github.com/prongbang/lazyxchacha
BenchmarkEncrypt-10 1220955 984.5 ns/op 944 B/op 5 allocs/op
BenchmarkDecrypt-10 1717482 696.1 ns/op 576 B/op 4 allocs/op
- 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()
sharedKey, _ := clientKx.Secret()
key, _ := hex.DecodeString(sharedKey)
plaintext := "text"
ciphertext, err := lazyXchacha.Encrypt(plaintext, key)
- Decrypt
lazyXchacha := lazyxchacha.New()
sharedKey, _ := serverKx.Secret()
key, _ := hex.DecodeString(sharedKey)
ciphertext := "f6a1bd8"
plaintext, err := lazyXchacha.Decrypt(ciphertext, key)