keyutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause, Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package keyutil contains utilities for managing public/private key pairs.

Index

Constants

View Source
const (
	// ECPrivateKeyBlockType is a possible value for pem.Block.Type.
	ECPrivateKeyBlockType = "EC PRIVATE KEY"
	// RSAPrivateKeyBlockType is a possible value for pem.Block.Type.
	RSAPrivateKeyBlockType = "RSA PRIVATE KEY"
	// PrivateKeyBlockType is a possible value for pem.Block.Type.
	PrivateKeyBlockType = "PRIVATE KEY"
	// PublicKeyBlockType is a possible value for pem.Block.Type.
	PublicKeyBlockType = "PUBLIC KEY"
)

Variables

This section is empty.

Functions

func LoadOrGenerateKeyFile

func LoadOrGenerateKeyFile(keyPath string) (data []byte, wasGenerated bool, err error)

LoadOrGenerateKeyFile looks for a key in the file at the given path. If it can't find one, it will generate a new key and store it there.

func MakeEllipticPrivateKeyPEM

func MakeEllipticPrivateKeyPEM() ([]byte, error)

MakeEllipticPrivateKeyPEM creates an ECDSA private key

func MarshalPrivateKeyToPEM

func MarshalPrivateKeyToPEM(privateKey crypto.PrivateKey) ([]byte, error)

MarshalPrivateKeyToPEM converts a known private key type of RSA or ECDSA to a PEM encoded block or returns an error.

func ParsePrivateKeyPEM

func ParsePrivateKeyPEM(keyData []byte) (interface{}, error)

ParsePrivateKeyPEM returns a private key parsed from a PEM block in the supplied data. Recognizes PEM blocks for "EC PRIVATE KEY", "RSA PRIVATE KEY", or "PRIVATE KEY"

func ParsePublicKeysPEM

func ParsePublicKeysPEM(keyData []byte) ([]interface{}, error)

ParsePublicKeysPEM is a helper function for reading an array of rsa.PublicKey or ecdsa.PublicKey from a PEM-encoded byte array. Reads public keys from both public and private key files.

func PrivateKeyFromFile

func PrivateKeyFromFile(file string) (interface{}, error)

PrivateKeyFromFile returns the private key in rsa.PrivateKey or ecdsa.PrivateKey format from a given PEM-encoded file. Returns an error if the file could not be read or if the private key could not be parsed.

func PublicKeysFromFile

func PublicKeysFromFile(file string) ([]interface{}, error)

PublicKeysFromFile returns the public keys in rsa.PublicKey or ecdsa.PublicKey format from a given PEM-encoded file. Reads public keys from both public and private key files.

func WriteKey

func WriteKey(keyPath string, data []byte) error

WriteKey writes the pem-encoded key data to keyPath. The key file will be created with file mode 0600. If the key file already exists, it will be overwritten. The parent directory of the keyPath will be created as needed with file mode 0755.

Types

This section is empty.

Jump to

Keyboard shortcuts

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