Skip to content

Conversation

@ydah
Copy link

@ydah ydah commented Jan 29, 2026

Summary

Implements JWE JSON Serialization as defined in RFC 7516 Section 7.2, supporting both General and Flattened formats.

Features

  • General JSON Serialization (RFC 7516 §7.2.1): Supports multiple recipients with a shared CEK
  • Flattened JSON Serialization (RFC 7516 §7.2.2): Simplified format for single recipient
  • Additional Authenticated Data (AAD): Custom AAD support per RFC 7516 §5.1
  • Key selection by kid: Automatic key selection using Key ID header parameter

New APIs

# Encryption
recipients = [JWE::Recipient.new(key: public_key, header: { 'alg' => 'RSA-OAEP' })]
JWE.encrypt_json(payload, recipients, protected_header: { enc: 'A128GCM' })
JWE.encrypt_json(payload, recipients, protected_header: { enc: 'A128GCM' }, format: :flattened)

# Decryption
result = JWE.decrypt_json(json_payload, private_key)
result.plaintext  # => decrypted data

References

## Summary

Implements JWE JSON Serialization as defined in RFC 7516 Section 7.2, supporting both General and Flattened formats.

## Features

- General JSON Serialization (RFC 7516 §7.2.1): Supports multiple recipients with a shared CEK
- Flattened JSON Serialization (RFC 7516 §7.2.2): Simplified format for single recipient
- Additional Authenticated Data (AAD): Custom AAD support per RFC 7516 §5.1
- Key selection by `kid`: Automatic key selection using Key ID header parameter

## New APIs

```ruby
# Encryption
recipients = [JWE::Recipient.new(key: public_key, header: { 'alg' => 'RSA-OAEP' })]
JWE.encrypt_json(payload, recipients, protected_header: { enc: 'A128GCM' })
JWE.encrypt_json(payload, recipients, protected_header: { enc: 'A128GCM' }, format: :flattened)

# Decryption
result = JWE.decrypt_json(json_payload, private_key)
result.plaintext  # => decrypted data
```

## References

- [RFC 7516 Section 7.2](https://datatracker.ietf.org/doc/html/rfc7516#section-7.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant