cryptoutils

package
v0.0.0-...-34af52f Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ECDSAPrivateKeyToPEM

func ECDSAPrivateKeyToPEM(w io.Writer, key *ecdsa.PrivateKey, public bool) error

WriteECDSAKeys writes the private key onto _w_ using the PEM format.

If _public_ is set to `true`, it will include public as well.

func ECDSAPublicKeyToPEM

func ECDSAPublicKeyToPEM(w io.Writer, key *ecdsa.PublicKey) error

WriteECDSAPublicKey writes the public key onto the _w_ `io.Writer`.

func PEMKeysFromFS

func PEMKeysFromFS(fsys fs.FS,
	dir string,
	glob string,
	parser PEMToKeyFactory,
	keyTypes ...string,
) (keys []interface{}, err error)

PEMKeysFromFS loads a set of keys stored in _PEM_ files on the _fsys_.

The _glob_ is a `glob.Glob` expression to capture one or more files (recursively), for example _"**.pem"_ will capture all files ending with _.pem_ recursively down folders. If empty string the default is _"**.pem"_

The dir string is in which subdirectory to start, if empty string, it will start at root level.

All other parameters are the same as the `PEMToKey` function.

func PEMToECDSAPrivateKey

func PEMToECDSAPrivateKey(data []byte) (key *ecdsa.PrivateKey, err error)

func PEMToECDSAPublicKey

func PEMToECDSAPublicKey(data []byte) (key *ecdsa.PublicKey, err error)

func PEMToKey

func PEMToKey(
	fqPath string,
	pemData []byte,
	parser PEMToKeyFactory,
	keyTypes ...string,
) (keys []interface{}, err error)

PEMToKey decods the _data_ and uses the _parser_ function to parse out the actual key(s).

The parameter _fqPath_ is optional to denote where the _pemData_ was taken from.

func PEMToRSAPrivateKey

func PEMToRSAPrivateKey(data []byte) (key *rsa.PrivateKey, err error)

func PEMToRSAPublicKey

func PEMToRSAPublicKey(data []byte) (key *rsa.PublicKey, err error)

func RSAPrivateKeyToPEM

func RSAPrivateKeyToPEM(w io.Writer, key *rsa.PrivateKey, public bool) error

WriteRSAKeys writes the private key onto _w_ using the PEM format.

If _public_ is set to `true`, it will include public as well.

func RSAPublicKeyToPEM

func RSAPublicKeyToPEM(w io.Writer, key *rsa.PublicKey) error

WriteRSAPublicKey writes the public key onto the _w_ `io.Writer`.

Types

type PEMToKeyFactory

type PEMToKeyFactory func(fqPath string, block *pem.Block) (key interface{}, stop bool, err error)

PEMToKeyFactory creates keys from a pem input.

If the function sets `true` in _stop_ or returns an error. The _PEM_ stops immediately. If it returns an error, the `PEMToKey` function will return the same error along with no keys.

If the function do not return a key, it will be silently ignored, hence it is possible to do selective decoding of keys.

The _fqPath_ may be empty string if the factory was invoked on data without any path information.

Jump to

Keyboard shortcuts

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