Skip to content

Commit ab10517

Browse files
committed
add GenerateBase64EdDSA helper
1 parent 883a655 commit ab10517

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

eddsa.go

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/rand"
66
"crypto/x509"
77
"encoding/asn1"
8+
"encoding/base64"
89
"encoding/pem"
910
"errors"
1011
"fmt"
@@ -220,3 +221,18 @@ func GenerateEdDSA() (ed25519.PublicKey, ed25519.PrivateKey, error) {
220221

221222
return publicPEM, privatePEM, nil
222223
}
224+
225+
// GenerateBase64EdDSA generates random public and private keys for ed25519.
226+
// The keys are returned as base64 encoded strings.
227+
func GenerateBase64EdDSA() (string, string, error) {
228+
_, priv, err := ed25519.GenerateKey(rand.Reader)
229+
if err != nil {
230+
return "", "", err
231+
}
232+
pub := ed25519.PrivateKey(priv).Public().(ed25519.PublicKey)
233+
234+
publicKey := base64.StdEncoding.EncodeToString(pub)
235+
privateKey := base64.StdEncoding.EncodeToString(priv)
236+
237+
return publicKey, privateKey, nil
238+
}

0 commit comments

Comments
 (0)