Cross-platform RSA & EC keypair generation, signing and verification - suitable for JWT, JOSE, and asymmetric cryptography.
Go to file
AJ ONeal a62ae2ea87 add inspect with OIDC key fetch 2020-11-25 03:10:33 -07:00
cmd/keypairs add inspect with OIDC key fetch 2020-11-25 03:10:33 -07:00
examples update documented import path 2020-05-10 13:11:26 -06:00
fixtures friendlier error reporting 2019-07-11 10:59:19 -06:00
keyfetch transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00
keyserve transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00
.gitignore fix flag parsing 2020-10-01 21:45:43 -06:00
.goreleaser.yml add goreleaser 2020-10-21 00:22:40 -06:00
AUTHORS update doc links and author info 2020-10-01 23:58:33 -06:00
LICENSE add MIT license 2019-08-19 14:48:28 -06:00
README.md doc: update README and help 2020-10-21 04:26:53 -06:00
cli_test.sh add verify subcommand 2020-10-02 02:44:26 -06:00
doc.go update canonical import path 2020-05-10 12:34:01 -06:00
generate.go add verify subcommand 2020-10-02 02:44:26 -06:00
go.mod update canonical import path 2020-05-10 12:34:01 -06:00
jwk.go add verify subcommand 2020-10-02 02:44:26 -06:00
jws.go add verify subcommand 2020-10-02 02:44:26 -06:00
keypairs.go transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00
keypairs_test.go friendlier error reporting 2019-07-11 10:59:19 -06:00
marshal.go transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00
mock.go add verify subcommand 2020-10-02 02:44:26 -06:00
sign.go transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00
verify.go transitioning to go1.15 PublicKey interface 2020-10-21 03:38:05 -06:00

README.md

keypairs

A cross-platform Command Line Tool and Golang Library that works with RSA, ECDSA, PEM, DER, JWK, and the JOSE suite.

Keypairs CLI

Generates, signs, and verifies with NIST-strength asymmetric keys.

# Generate JSON Web Keys (JWKs)
keypairs gen > key.jwk.json 2> pub.jwk.json

# Generate PEM (or DER) Keys, by extension
keypairs gen --key key.pem --pub pub.pem

# Sign a payload
keypairs sign key.jwk.json --exp 1h '{ "sub": "me@example.com" }' > token.jwt 2> sig.jws

# Verify a signature
keypairs verify pub.jwk.json token.jwt

Cheat Sheet at https://webinstall.dev/keypairs.

Install

Mac, Linux:

curl -sS https://webinstall.dev/keypairs | bash

Windows 10:

curl.exe -A MS https://webinstall.dev/keypairs | powershell

Keypairs Go Library

JSON Web Key (JWK) support and type safety lightly placed over top of Go's crypto/ecdsa and crypto/rsa

Useful for JWT, JOSE, etc.

key, err := keypairs.ParsePrivateKey(bytesForJWKOrPEMOrDER)

pub, err := keypairs.ParsePublicKey(bytesForJWKOrPEMOrDER)

jwk, err := keypairs.MarshalJWKPublicKey(pub, time.Now().Add(2 * time.Day))

kid, err := keypairs.ThumbprintPublicKey(pub)

GoDoc API Documentation

See https://pkg.go.dev/git.rootprojects.org/root/keypairs

Philosophy

Go's standard library is great.

Go has excellent crytography support and provides wonderful primitives for dealing with them.

I prefer to stay as close to Go's crypto package as possible, just adding a light touch for JWT support and type safety.

Type Safety

crypto.PublicKey is a "marker interface", meaning that it is not typesafe!

go-keypairs defines type keypairs.PrivateKey interface { Public() crypto.PublicKey }, which is implemented by crypto/rsa and crypto/ecdsa (but not crypto/dsa, which we really don't care that much about).

Go1.15 will add [PublicKey.Equal(crypto.PublicKey)](https://github.com/golang/go/issues/21704), which will make it possible to remove the additional wrapper over PublicKey and use an interface instead.

Since there are no common methods between rsa.PublicKey and ecdsa.PublicKey, go-keypairs lightly wraps each to implement Thumbprint() string (part of the JOSE/JWK spec).

JSON Web Key (JWK) as a "codec"

Although there are many, many ways that JWKs could be interpreted (possibly why they haven't made it into the standard library), go-keypairs follows the basic pattern of encoding/x509 to Parse and Marshal only the most basic and most meaningful parts of a key.

I highly recommend that you use Thumbprint() for KeyID you also get the benefit of not losing information when encoding and decoding between the ASN.1, x509, PEM, and JWK formats.

LICENSE

Copyright (c) 2020-present AJ ONeal
Copyright (c) 2018-2019 Big Squid, Inc.

This work is licensed under the terms of the MIT license.
For a copy, see https://opensource.org/licenses/MIT.