crystal-jose

JOSE (RFC 7515-7519) implementation in pure Crystal — JWK, JWS, JWE. Built to support crystal-clevis-geli (Tang client).

= crystal-jose :toc: left :toclevels: 2 :source-highlighter: rouge

image:https://github.com/aloli-crystal/crystal-jose/actions/workflows/ci.yml/badge.svg[CI,link=https://github.com/aloli-crystal/crystal-jose/actions/workflows/ci.yml]

JOSE (RFC 7515-7519) implementation in pure Crystal: JSON Web Signature (JWS), JSON Web Encryption (JWE), JSON Web Key (JWK).

French version: link:README.fr.adoc[README.fr.adoc].

== Why

crystal-jose exists primarily to support https://github.com/aloli-crystal/crystal-clevis-geli[crystal-clevis-geli], the Tang client for FreeBSD GELI volumes. Initial scope is intentionally minimal — only what the Tang protocol needs:

  • JWK: thumbprints (RFC 7638), serialization, ECDH key types (P-256, P-384, P-521).
  • JWS: ES256, ES512 (signature & verification).
  • JWE: ECDH-ES key agreement, A256GCM content encryption.

Out of v0.1 scope (may be added later if needed):

  • RSA-based algorithms (RSA-OAEP, RS256, …).
  • EdDSA (Ed25519).
  • Full JWT validation (exp, nbf, aud, …).
  • JWKS endpoints (key discovery over HTTP).

== Installation

Add to your shard.yml:

[source,yaml]

dependencies: crystal-jose: github: aloli-crystal/crystal-jose version: ~> 0.1

Then shards install.

== Usage

[source,crystal]

require "crystal-jose"

=== JWK ============================================================

key = CrystalJose::JWK::ECKey.generate(CrystalJose::JWK::Curve::P256) key.thumbprint_base64url # => "cn-I_WNMClehiVp51i_0VpOENW1upEerA8sEam5hn-s" key.public_key.to_json # => {"kty":"EC","crv":"P-256","x":"...","y":"..."}

Parse a JWK (e.g. from a Tang advertisement).

peer = CrystalJose::JWK::ECKey.from_json(jwk_string)

=== JWS ============================================================

jws = CrystalJose::JWS.sign("payload", CrystalJose::JWS::Algorithm::ES256, key) plaintext = CrystalJose::JWS.verify(jws, key.public_key)

=== JWE ============================================================

jwe = CrystalJose::JWE.encrypt("secret", peer.public_key) plaintext = CrystalJose::JWE.decrypt(jwe, peer)

== Development

[source,shell]

shards install crystal spec crystal tool format --check bin/ameba

== Contributing

. Fork the repository. . Create a feature branch from production. . Run crystal tool format src/ spec/ before each commit. . Open a pull request against production.

== License

MIT — see link:LICENSE[LICENSE].

== References

Repository

crystal-jose

Owner
Statistic
  • 0
  • 0
  • 0
  • 2
  • 1
  • about 7 hours ago
  • April 27, 2026
License

MIT License

Links
Synced at

Mon, 27 Apr 2026 15:33:10 GMT

Languages