keyutil

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 12 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 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 {
	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. Use 'fields' to set additional fields like kty, and kid. alg 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. Use 'fields' to set additional fields like kty, and kid. alg is set based on the passed in PrivateKey.

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