Class AnkaJoseUtil
This class exists because ANKASecure exposes only General JSON Serialization on its REST API. Clients that receive a Compact JOSE payload from a third-party producer (Nimbus JOSE+JWT, jose4j, python-jose, an OAuth issuer, etc.) MUST convert it to General JSON before invoking ANKASecure's decrypt/verify/reencrypt endpoints. Conversely, clients that wish to feed an ANKASecure-produced JOSE artefact to a Compact-only consumer (typical JWT-side tooling) MUST convert the other direction.
Stateless, thread-safe: the ObjectMapper is
private static final and no other state is held. No I/O. No HTTP.
No dependency on the ANKASecure server. Safe to call from any thread without
synchronization.
Multi-recipient / multi-signature rejection: General JSON
supports multi-recipient JWE and multi-signature JWS; Compact does not
(RFC 7516 Section 7.1 / RFC 7515 Section 7.1 are single-recipient/single-signature only).
Attempting to convert a multi-recipient/multi-signature General JSON to
Compact throws IllegalArgumentException with a descriptive message
— the helper NEVER silently drops recipients or signatures.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcompactJweToGeneral(String compactJwe) Converts a Compact JWE (5 dot-separated base64url segments) into the General JSON Serialization form as a JSON string.static StringcompactJwsToGeneral(String compactJws) Converts a Compact JWS (3 dot-separated base64url segments) into the General JSON Serialization form as a JSON string.static StringgeneralJweToCompact(String generalJsonJwe) Converts a General JSON Serialization JWE (as a JSON string) into the Compact Serialization (5 dot-separated segments).static StringgeneralJwsToCompact(String generalJsonJws) Converts a General JSON Serialization JWS (as a JSON string) into the Compact Serialization (3 dot-separated segments).
-
Method Details
-
compactJweToGeneral
Converts a Compact JWE (5 dot-separated base64url segments) into the General JSON Serialization form as a JSON string.An empty JWE Encrypted Key segment (Direct Encryption
alg=diror Direct Key Agreementalg=ECDH-ES) yields a recipient with NOencrypted_keymember: RFC 7516 Section 7.2.1 requires the member to be absent when the JWE Encrypted Key is empty.The recipient carries no
headermember. Every header parameter of a Compact JWE lives in its protected header, and RFC 7516 Section 7.2.1 requires the protected, shared unprotected and per-recipient headers to be disjoint: copyingalgorkidinto the recipient would name each twice, which a conforming reader refuses.- Throws:
IllegalArgumentException- if the input has the wrong segment count
-
generalJweToCompact
Converts a General JSON Serialization JWE (as a JSON string) into the Compact Serialization (5 dot-separated segments).A recipient without
encrypted_keyhas an empty JWE Encrypted Key (RFC 7516 Section 7.2.1), which Compact Serialization carries as an empty second segment (RFC 7516 Section 7.1).- Throws:
IllegalArgumentException- if the General JSON has more than one recipient (multi-recipient cannot be represented in Compact form — RFC 7516 Section 7.1 is single-recipient only), or if the recipient'sencrypted_keyis present but is not a string
-
compactJwsToGeneral
Converts a Compact JWS (3 dot-separated base64url segments) into the General JSON Serialization form as a JSON string. -
generalJwsToCompact
Converts a General JSON Serialization JWS (as a JSON string) into the Compact Serialization (3 dot-separated segments).- Throws:
IllegalArgumentException- if the General JSON has more than one signature
-