Class AnkaJoseUtil

java.lang.Object
co.ankatech.ankasecure.sdk.jose.AnkaJoseUtil

public final class AnkaJoseUtil extends Object
Pure client-side conversion helpers between the JOSE Compact Serialization (RFC 7516 §7.1 for JWE / RFC 7515 §7.1 for JWS) and the General JSON Serialization (RFC 7516 §7.2 / RFC 7515 §7.2) used by ANKASecure on the wire.

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 ANKA's decrypt/verify/reencrypt endpoints. Conversely, clients that wish to feed an ANKA-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 ANKA 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 §7.1 / RFC 7515 §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 Details

    • compactJweToGeneral

      public static String compactJweToGeneral(String compactJwe)
      Converts a Compact JWE (5 dot-separated base64url segments) into the General JSON Serialization form as a JSON string.
      Throws:
      IllegalArgumentException - if the input has the wrong segment count
    • generalJweToCompact

      public static String generalJweToCompact(String generalJsonJwe)
      Converts a General JSON Serialization JWE (as a JSON string) into the Compact Serialization (5 dot-separated segments).
      Throws:
      IllegalArgumentException - if the General JSON has more than one recipient (multi-recipient cannot be represented in Compact form — RFC 7516 §7.1 is single-recipient only)
    • compactJwsToGeneral

      public static String compactJwsToGeneral(String compactJws)
      Converts a Compact JWS (3 dot-separated base64url segments) into the General JSON Serialization form as a JSON string.
    • generalJwsToCompact

      public static String generalJwsToCompact(String generalJsonJws)
      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