edkey

package module
v0.0.0-...-ccc67b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

README

edkey

edkey formats an ED25519 private key in OpenSSH's PEM format.

Please see example.go for an example.

Installation

go get github.com/magisterquis/edkey@latest

Quickstart

_, kr, err := ed25519.GenerateKey(nil)
if nil != err {
        log.Fatalf("Error generating key: %s", err)
}
p, err := edkey.ToPEM(kr, "")
if nil != err {
        log.Fatalf("Error PEMifying key: %s", err)
}
if err := os.WriteFile("id_ed25519", p, 0600); nil != err {
        log.Fatalf("Error writing key to file: %s", err)
}

Credit

Many thanks to mikesmitty for the original version of this library.

Documentation

Overview

Package edkey converts ed25519 private keys to OpenSSH PEM format.

Example
/* Predictable random source.  Please don't do this in real code. */
rs := rand.New(rand.NewSource(0))

/* Generate an ED25519 key and PEMify it. */
_, kr, err := ed25519.GenerateKey(rs)
if nil != err {
	log.Fatalf("Error generating key: %s", err)
}
spem, err := ToPEM(kr, "A fancy example key")
if nil != err {
	log.Fatalf("Error converting to OpenSSH PEM format: %s", err)
}
/* spem can now be written to disk and passed to ssh -i. */

/* We can also use it with x/crypto/ssh. */
s, err := ssh.ParsePrivateKey(spem)
if nil != err {
	log.Fatalf("Parsing PEM: %s", err)
}
fmt.Printf(
	"Fingerprint: %s\n",
	ssh.FingerprintSHA256(s.PublicKey()),
)
Output:

Fingerprint: SHA256:Wa1InoB8MuILNZy9CjDRvHn9c6afuXSwS7Vm+/addOA

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToPEM

func ToPEM(key ed25519.PrivateKey, comment string) ([]byte, error)

ToPEM encodes a ed25519 private key into the OpenSSH PEM private key format, optionally setting a comment (ssh-keygen -C -style). The returned slice is suitable to be written to a file and passed to OpenSSH via -i/-oIdentityFile.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL