A simple way to do x25519 key agreements.
- Easy to use
- Use curve25519.X25519 for multiplication and not other deprecated methods.
- Small code base
- Use slices of byte instead of [32]byte
go get github.com/HirbodBehnam/EasyX25519
This library has three functions.
NewX25519
: Creates a fresh key pair for x25519 key exchange algorithm.NewX25519FromPrivateKey
: Creates a key pair from private key(*KeyPair) GenerateSharedSecret
: Pass the other recipient's public key to this command to generate a shared secret
https://pkg.go.dev/github.com/HirbodBehnam/EasyX25519
Here is a small example from test file:
package main
import (
"github.com/HirbodBehnam/EasyX25519"
"log"
)
func main() {
// generate keys
alice, err := x25519.NewX25519()
if err != nil{
log.Fatalf("could not genearte key for alice: %s",err.Error())
}
log.Printf("Alice public key %x",alice.PublicKey)
bob, err := x25519.NewX25519()
if err != nil{
log.Fatalf("could not genearte key for bob: %s",err.Error())
}
log.Printf("Bob public key %x",bob.PublicKey)
// calculate secret
s1, err := alice.GenerateSharedSecret(bob.PublicKey)
if err != nil{
log.Fatalf("could not get secret for alice: %s",err.Error())
}
s2, err := bob.GenerateSharedSecret(alice.PublicKey)
if err != nil{
log.Fatalf("could not get secret for bob: %s",err.Error())
}
// check if they match
log.Printf("Alice secret %x",s1)
log.Printf("Bob secret %x",s2)
}