Add JSON Serialization support (General and Flattened)#47
Open
ydah wants to merge 1 commit intojwt:masterfrom
Open
Add JSON Serialization support (General and Flattened)#47ydah wants to merge 1 commit intojwt:masterfrom
ydah wants to merge 1 commit intojwt:masterfrom
Conversation
## 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements JWE JSON Serialization as defined in RFC 7516 Section 7.2, supporting both General and Flattened formats.
Features
kid: Automatic key selection using Key ID header parameterNew APIs
References