jwker

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 11 Imported by: 0

README

Jwker

This is a command line tool to easily convert keys between the PEM and JWK file formats.

Usage

Convert from PEM to JWK format:

jwker my-key.pem my-key.jwk
jwker my-key.pem | pbcopy
cat my-key.pem | jwker > my-key.jwk

A complete example for creating a new keypair, saving the public key as a JWK and the private key as a PEM, but with a passphrase:

openssl ecparam -genkey -name prime256v1 \
| tee >(openssl ec -pubout | jwker > key.pub.jwk) \
| openssl ec -aes256 -out key.prv.pem

Convert from JWK to PEM format:

jwker my-key.jwk my-key.pwm
jwker my-key.jwk | pbcopy
cat my-key.jwk | jwker

Installation

If you have go installed:

go install github.com/jphastings/jwker@latest

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWK

type JWK struct {
	KeyType string `json:"kty"`

	// EC, Public
	Curve string `json:"crv,omitempty"`
	X     string `json:"x,omitempty"`
	Y     string `json:"y,omitempty"`

	// RSA, Public
	Modulus        string `json:"n,omitempty"`
	PublicExponent string `json:"e,omitempty"`

	// EC & RSA, Private
	D string `json:"d,omitempty"`

	// RSA, Private
	Prime1      string `json:"p,omitempty"`
	Prime2      string `json:"q,omitempty"`
	Exponent1   string `json:"dp,omitempty"`
	Exponent2   string `json:"dq,omitempty"`
	Coefficient string `json:"qi,omitempty"`
}

JWK represents a (simplified version of a) JSON Web Key.

func ParseJWK

func ParseJWK(bytes []byte) (*JWK, error)

ParseJWK parses the bytes of a JWK file and provides a *JWK struct.

func ParsePEM

func ParsePEM(pemBytes []byte) (*JWK, error)

ParsePEM parses the bytes of an unencrypted PEM file and produces a *JWK struct.

func PrivateKeyToJWK

func PrivateKeyToJWK(key any) (*JWK, error)

PrivateKeyToJWK converts any private key type created by the crypto x509 package into a JWK. This includes *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (not a pointer), and *ecdh.PublicKey.

func PublicKeyToJWK

func PublicKeyToJWK(key any) (*JWK, error)

PublicKeyToJWK converts any public key type created by the crypto x509 package into a JWK. This includes *rsa.PublicKey, *dsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (not a pointer), or *ecdh.PublicKey (for X25519).

func (*JWK) Key

func (jwk *JWK) Key() (any, error)

func (*JWK) PEM

func (jwk *JWK) PEM() ([]byte, error)

func (*JWK) String

func (j *JWK) String() (string, error)

String returns the JSON representation of the JWK.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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