Skip to content

Commit

Permalink
add GenerateBase64EdDSA helper
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Nov 10, 2023
1 parent 883a655 commit ab10517
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions eddsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/rand"
"crypto/x509"
"encoding/asn1"
"encoding/base64"
"encoding/pem"
"errors"
"fmt"
Expand Down Expand Up @@ -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
}

0 comments on commit ab10517

Please sign in to comment.