keyutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2025 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package keyutil provides some basic PEM and JWK key handling without dependencies. It is not meant as a replacement for a full key handling library.

Index

Constants

View Source
const (
	KeyTypeEC  = "EC"
	KeyTypeOct = "oct"
)

Variables

This section is empty.

Functions

func MustReadPrivateKey

func MustReadPrivateKey(encodedPrivateKey []byte) crypto.PrivateKey

func MustReadPrivateKeyFile

func MustReadPrivateKeyFile(pkFile string) crypto.PrivateKey

MustReadPrivateKeyFile decodes a PEM encoded private key file and parses into a crypto.PrivateKey or panics.

func MustReadPrivateKeyFileECDSA added in v1.2.0

func MustReadPrivateKeyFileECDSA(pkFile string) *ecdsa.PrivateKey

func MustReadPrivateKeyFileED25519 added in v1.2.0

func MustReadPrivateKeyFileED25519(pkFile string) ed25519.PrivateKey

func MustReadPublicKeyFile

func MustReadPublicKeyFile(pubkeyFile string) crypto.PublicKey

MustReadPublicKeyFile reads a PEM encoded public key file or panics

func ReadPrivateKey

func ReadPrivateKey(encodedPrivateKey []byte) (crypto.PrivateKey, error)

ReadPrivateKey decoded a PEM encoded private key and parses into a crypto.PrivateKey.

func ReadPrivateKeyFile

func ReadPrivateKeyFile(pkFile string) (crypto.PrivateKey, error)

ReadPrivateKeyFile opens the given file and calls ReadPrivateKey to return a crypto.PrivateKey

func ReadPublicKey

func ReadPublicKey(encodedPubkey []byte) (crypto.PublicKey, error)

ReadPublicKey decodes a PEM encoded public key and parses into crypto.PublicKey

func ReadPublicKeyFile

func ReadPublicKeyFile(pubkeyFile string) (crypto.PublicKey, error)

ReadPublicKeyFile reads a PEM encdoded public key file and parses into crypto.PublicKey

Types

type JWK added in v1.0.3

type JWK struct {
	// Common fields are duplicated as struct members for better usability.
	KeyType   string // 'kty' - "EC", "RSA", "oct"
	Algorithm string // 'alg'
	KeyID     string // 'kid'
	// contains filtered or unexported fields
}

JWK provides basic data and usage for a JWK.

func FromPrivateKey added in v1.0.3

func FromPrivateKey(pkey crypto.PrivateKey) (JWK, error)

FromPrivateKey creates a JWK from a crypto.PrivateKey. 'kty' is set based on the passed in PrivateKey.

func ReadJWK added in v1.0.3

func ReadJWK(jwkBytes []byte) (JWK, error)

func ReadJWKFile added in v1.0.3

func ReadJWKFile(jwkFile string) (JWK, error)

func ReadJWKFromPEM added in v1.0.3

func ReadJWKFromPEM(pkeyBytes []byte) (JWK, error)

ReadJWKFromPEM converts a PEM encoded private key to JWK. 'kty' is set based on the passed in PrivateKey type.

func (JWK) MarshalJSON added in v1.0.3

func (j JWK) MarshalJSON() ([]byte, error)

func (*JWK) PrivateKey added in v1.0.3

func (ji *JWK) PrivateKey() (crypto.PrivateKey, error)

func (*JWK) PublicKey added in v1.0.3

func (ji *JWK) PublicKey() (crypto.PublicKey, error)

func (*JWK) PublicKeyJWK added in v1.1.3

func (ji *JWK) PublicKeyJWK() (JWK, error)

func (*JWK) SecretKey added in v1.0.3

func (ji *JWK) SecretKey() ([]byte, error)

Jump to

Keyboard shortcuts

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