sshkey

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownAlgorithm    = fmt.Errorf("sshkey: unknown private key algorithm")
	ErrInvalidRSAKeySize   = fmt.Errorf("sshkey: invalid private key rsa size: must be more than 1024")
	ErrInvalidECDSAKeySize = fmt.Errorf("sshkey: invalid private key ecdsa size, must be one of 256, 384 or 521")
	ErrInvalidDSAKeySize   = fmt.Errorf("sshkey: invalid private key dsa size, must be one of 1024, 2048 or 3072")
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm int
const (
	RSA Algorithm = iota
	DSA
	ECDSA
	ED25519
)

func AlgorithmString

func AlgorithmString(s string) (Algorithm, error)

AlgorithmString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func AlgorithmValues

func AlgorithmValues() []Algorithm

AlgorithmValues returns all values of the enum

func (Algorithm) IsAAlgorithm

func (i Algorithm) IsAAlgorithm() bool

IsAAlgorithm returns "true" if the value is listed in the enum definition. "false" otherwise

func (Algorithm) String

func (i Algorithm) String() string

type Pair

type Pair struct {
	Private []byte
	Public  []byte
}

Pair represents an ssh key pair, as in

func GeneratePair

func GeneratePair(t Algorithm, rand io.Reader, bits int) (*Pair, error)

GeneratePair generates a Private/Public key pair using algorithm t.

When rand is nil "crypto/rand".Reader will be used.

bits specifies the number of bits in the key to create. For RSA keys, the minimum size is 1024 bits and the default is 3072 bits. Generally, 3072 bits is considered sufficient. DSA keys must be exactly 1024 bits - or 2 or 3 times that - as specified by FIPS 186-2. For ECDSA keys, bits determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will fail. Ed25519 keys have a fixed length and the bits will be ignored.

func NewPair

func NewPair(public, private interface{}) (*Pair, error)

func PairFromDSA

func PairFromDSA(key *dsa.PrivateKey) (*Pair, error)

PairFromDSA marshalls a valid pair of openssh pem for dsa keypairs. x509.MarshalPKCS8PrivateKey does not know how to deal with dsa keys.

func PairFromED25519

func PairFromED25519(public ed25519.PublicKey, private ed25519.PrivateKey) (*Pair, error)

PairFromED25519 marshalls a valid pair of openssh pem for ED25519 keypairs. NewPair can handle ed25519 pairs but generates the wrong format apparently: `Load key "id_ed25519": invalid format` is the error that happens when I try to ssh with such a key.

Jump to

Keyboard shortcuts

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