From ab10517a5e750b8829578a68d8b4bb1ad076c5a3 Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Fri, 10 Nov 2023 22:49:29 +0200 Subject: [PATCH] add GenerateBase64EdDSA helper --- eddsa.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/eddsa.go b/eddsa.go index 8b07efc..f59edd7 100644 --- a/eddsa.go +++ b/eddsa.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "crypto/x509" "encoding/asn1" + "encoding/base64" "encoding/pem" "errors" "fmt" @@ -220,3 +221,18 @@ func GenerateEdDSA() (ed25519.PublicKey, ed25519.PrivateKey, error) { return publicPEM, privatePEM, nil } + +// GenerateBase64EdDSA generates random public and private keys for ed25519. +// The keys are returned as base64 encoded strings. +func GenerateBase64EdDSA() (string, string, error) { + _, priv, err := ed25519.GenerateKey(rand.Reader) + if err != nil { + return "", "", err + } + pub := ed25519.PrivateKey(priv).Public().(ed25519.PublicKey) + + publicKey := base64.StdEncoding.EncodeToString(pub) + privateKey := base64.StdEncoding.EncodeToString(priv) + + return publicKey, privateKey, nil +}