keybox

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: MIT Imports: 6 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

test Go Reference Go Report Card codecov

keybox-go

keybox-go is a tiny library for interacting with private and public keys in Go.

The initial implementation was inspired by github.com/dgrijalva/jwt-go, but has greatly superseeded it (e.g. by supporting password protected keys).

Download:

go get github.com/kernle32dll/keybox-go

Detailed documentation can be found on pkg.go.dev.

Compatibility

keybox-go is automatically tested against Go 1.15.X, 1.16.X and 1.17.X.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCertificateMustBePEMEncoded indicates that a given data block was not a PEM encoded block.
	ErrCertificateMustBePEMEncoded = errors.New("invalid Certificate: Certificate must be PEM encoded")

	// ErrNotACertificate indicates that a given PEM block did not contain a known certificate format.
	ErrNotACertificate = errors.New("invalid Key: PEM block must be a x509 certificate")
)
View Source
var (
	// ErrKeyMustBePEMEncoded indicates that a given data block was not a PEM encoded block.
	ErrKeyMustBePEMEncoded = errors.New("invalid Key: Key must be PEM encoded")

	// ErrNotAPrivateKey indicates that a given PEM block did not contain a known private key format.
	ErrNotAPrivateKey = errors.New("invalid Key: PEM block must be a PKCS #1, PKCS #8 or SEC 1 private key")

	// ErrUnknownEncryption indicates that the given PEM block was not encrypted in a known format,
	// or not encrypted in the first place.
	ErrUnknownEncryption = errors.New("invalid encryption: PEM block is encrypted in a unknown format, or not encrypted at all")
)
View Source
var (
	// ErrNotAPublicKey indicates that a given PEM block did not contain a known public key format.
	ErrNotAPublicKey = errors.New("invalid Key: PEM block must be a PKIX or PKCS #1 public key")
)

Functions

func LoadCertificate added in v1.1.0

func LoadCertificate(path string) (*x509.Certificate, error)

LoadCertificate tries to load a certificate from a given path.

func LoadCertificateWithPassword added in v1.1.0

func LoadCertificateWithPassword(path string, password []byte) (*x509.Certificate, error)

LoadCertificateWithPassword tries to load a certificate from a given path with a password.

func LoadPrivateKey

func LoadPrivateKey(path string) (crypto.PrivateKey, error)

LoadPrivateKey tries to load a private key from a given path.

func LoadPrivateKeyWithPassword

func LoadPrivateKeyWithPassword(path string, password []byte) (crypto.PrivateKey, error)

LoadPrivateKeyWithPassword tries to load a private key from a given path with a password.

func LoadPublicKey

func LoadPublicKey(path string) (crypto.PublicKey, error)

LoadPublicKey tries to load a public key from a given path.

func LoadPublicKeyWithPassword

func LoadPublicKeyWithPassword(path string, password []byte) (crypto.PublicKey, error)

LoadPublicKeyWithPassword tries to load a public key from a given path with a password.

func ParseCertificateFromDERBytes added in v1.1.0

func ParseCertificateFromDERBytes(derBytes []byte) (*x509.Certificate, error)

ParseCertificateFromDERBytes parse a given byte array for a ASN.1 DER encoded PKIX or PKCS #1 public key. Will return ErrNotACertificate if the given byte array is not in properly encoded DER form, or is not a known public key format.

func ParseCertificateFromEncryptedPEMBytes added in v1.1.0

func ParseCertificateFromEncryptedPEMBytes(pemBytes []byte, password []byte) (*x509.Certificate, error)

ParseCertificateFromEncryptedPEMBytes parses and decrypts a given byte array and password to a PEM block, and parses that block for a known certificate. Will return ErrCertificateMustBePEMEncoded if the given byte array is not a valid PEM block, or ErrUnknownEncryption if the byte array was encrypted in an unknown format, or not encrypted at all. Note: Usage of RFC 1423 encrypted PEM blocks is deprecated since Go 1.16!

func ParseCertificateFromPEMBytes added in v1.1.0

func ParseCertificateFromPEMBytes(pemBytes []byte) (*x509.Certificate, error)

ParseCertificateFromPEMBytes parses a given byte array to a PEM block, and parses that block for a known certificate. Will return ErrCertificateMustBePEMEncoded if the given byte array is not a valid PEM block.

func ParsePrivateKeyFromDERBytes

func ParsePrivateKeyFromDERBytes(derBytes []byte) (crypto.PrivateKey, error)

ParsePrivateKeyFromDERBytes parse a given byte array for a ASN.1 DER encoded PKCS #1, PKCS #8 or SEC 1 private key. Will return ErrNotAPrivateKey if the given byte array is not in properly encoded DER form, or is not a known private key format.

func ParsePrivateKeyFromEncryptedPEMBytes

func ParsePrivateKeyFromEncryptedPEMBytes(pemBytes []byte, password []byte) (crypto.PrivateKey, error)

ParsePrivateKeyFromEncryptedPEMBytes parses and decrypts a given byte array and password to a PEM block, and parses that block for a known private key (see ParsePrivateKeyFromDERBytes). Will return ErrKeyMustBePEMEncoded if the given byte array is not a valid PEM block, or ErrUnknownEncryption if the byte array was encrypted in an unknown format, or not encrypted at all. Note: Usage of RFC 1423 encrypted PEM blocks is deprecated since Go 1.16! Use PKCS #8 instead.

func ParsePrivateKeyFromPEMBytes

func ParsePrivateKeyFromPEMBytes(pemBytes []byte) (crypto.PrivateKey, error)

ParsePrivateKeyFromPEMBytes parses a given byte array to a PEM block, and parses that block for a known private key (see ParsePrivateKeyFromDERBytes). Will return ErrKeyMustBePEMEncoded if the given byte array is not a valid PEM block.

func ParsePublicKeyFromDERBytes

func ParsePublicKeyFromDERBytes(derBytes []byte) (crypto.PublicKey, error)

ParsePublicKeyFromDERBytes parse a given byte array for a ASN.1 DER encoded PKIX or PKCS #1 public key. Will return ErrNotAPublicKey if the given byte array is not in properly encoded DER form, or is not a known public key format.

func ParsePublicKeyFromEncryptedPEMBytes

func ParsePublicKeyFromEncryptedPEMBytes(pemBytes []byte, password []byte) (crypto.PublicKey, error)

ParsePublicKeyFromEncryptedPEMBytes parses and decrypts a given byte array and password to a PEM block, and parses that block for a known public key (see ParsePublicKeyFromDERBytes). Will return ErrKeyMustBePEMEncoded if the given byte array is not a valid PEM block, or ErrUnknownEncryption if the byte array was encrypted in an unknown format, or not encrypted at all. Note: Usage of RFC 1423 encrypted PEM blocks is deprecated since Go 1.16!

func ParsePublicKeyFromPEMBytes

func ParsePublicKeyFromPEMBytes(pemBytes []byte) (crypto.PublicKey, error)

ParsePublicKeyFromPEMBytes parses a given byte array to a PEM block, and parses that block for a known public key (see ParsePublicKeyFromDERBytes). Will return ErrKeyMustBePEMEncoded if the given byte array is not a valid PEM block.

Types

This section is empty.

Jump to

Keyboard shortcuts

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