Business Data Encryption

Register recipient keys and process encrypted business responses with JWE Compact, RSA-OAEP-256, and A256GCM.

This guide describes the business-response encryption profile in ELECQ Open Access. Read the Authentication Guide first to obtain a token using authorization code or client credentials.

When this profile applies

Use this profile for business APIs whose successful response explicitly declares Content-Type: application/jose. Existing APIs retain the response formats shown in their API Reference.

List Organization Devices under Application Access requires this profile for every successful page, including requests that select only basic fields. Obtain a token for the current organization using grant_type=client_credentials at the shared Token endpoint, then send Accept: application/jose. Encryption is mandatory; the request Content-Type does not switch it on or off, and there is no plaintext success option.

OAuth 2.0 and scopes determine which operations and data you may access. JWE protects an authorized business response. Continue to use HTTPS and Bearer authentication. The Token endpoint returns ordinary JSON and is not encrypted with this business-data profile. Choosing client_credentials alone does not activate JWE.

For a paginated business API using this profile, encrypt the complete page's UTF-8 JSON, including device records and pagination metadata such as nextCursor and hasMore. Do not encrypt each device field separately. Preserve device identifiers, PINs, and random codes as strings, including leading zeroes.

Register the recipient public key

  1. Generate an RSA key pair with a key size between 2048 and 8192 bits, inclusive.
  2. Export the public key as a PEM file (.pem) and provide it to ELECQ together with your Application Access client ID. State the client ID when submitting the file; it is not an input when generating the RSA key pair.
  3. Keep the private key in your backend's trusted key configuration. Never send your private key to ELECQ.
  4. Wait for ELECQ to confirm activation and provide the key identifier (kid). Associate that identifier with the matching private key in your backend.

A PEM public key file typically has the following form. The middle line below is a placeholder, not a usable public key:

-----BEGIN PUBLIC KEY-----
BASE64_ENCODED_PUBLIC_KEY
-----END PUBLIC KEY-----

Each client has one active recipient public key. Key registration is per client ID, including when multiple clients belong to the same organization. The device-query request cannot supply an arbitrary replacement key.

After ELECQ confirms activation, request a page from List Organization Devices. Verify HTTP 200, Content-Type: application/jose, the expected protected-header kid, and successful decryption with authentication-tag verification. A successful Token request alone does not verify recipient-key configuration.

These keys have different purposes:

Credential or keyPurpose
OAuth2 client_id and client_secretAuthenticate your application at the Token endpoint.
OAuth2 access_tokenAuthorize API requests through the Bearer header.
Registered recipient RSA public keyAllow ELECQ to encrypt a response for your application.
Recipient RSA private keyDecrypt responses in your backend; it remains with you.
ELECQ's token-signing keys at /api/v1/oauth2/jwksVerify OAuth2 token signatures; these are separate from recipient encryption keys.

Encryption profile

Use a JOSE library that supports the exact combination below. Reject other algorithms instead of accepting a downgrade.

ParameterRequired value
SerializationJWE Compact, one recipient
Key encryption (alg)RSA-OAEP-256, with SHA-256 for both OAEP and MGF1
Content encryption (enc)A256GCM, AES-256-GCM
Content encryption key (CEK)Fresh 32-byte key for each generated response
Initialization vector (IV)Fresh 12-byte IV for each generated response
Authentication tag16 bytes
PlaintextThe complete business response JSON encoded as UTF-8
CompressionNot used; omit zip
Binary encodingBase64url without padding

Generate the CEK and IV with a cryptographically secure random generator. Never reuse a CEK/IV pair. The algorithm definitions are in RFC 7518: RSA-OAEP-256 and RFC 7518: AES-GCM.

Protected header

Example JSON before Base64url encoding:

{
  "alg": "RSA-OAEP-256",
  "enc": "A256GCM",
  "kid": "recipient-key-01",
  "cty": "application/json"
}

The protected header is readable metadata inside the JWE body, not an HTTP response header. It contains no secrets. Its encoded value is authenticated as additional authenticated data (AAD); let your JOSE library handle the JWE encoding and verification.

HTTP response format

A successful encrypted response has Content-Type: application/jose and Cache-Control: no-store. Its body is one JWE Compact string with five non-empty Base64url segments separated by periods, as defined in RFC 7516: Compact Serialization.

protected_header.encrypted_key.iv.ciphertext.tag
SegmentContents
protected_headerBase64url-encoded UTF-8 protected-header JSON
encrypted_keyThe CEK encrypted with the registered recipient RSA public key
ivThe AES-GCM initialization vector
ciphertextAES-GCM ciphertext of the complete business JSON
tagThe AES-GCM authentication tag

The following is a format illustration with placeholders, not a decryptable test vector:

HTTP/1.1 200 OK
Content-Type: application/jose
Cache-Control: no-store

BASE64URL_PROTECTED_HEADER.BASE64URL_ENCRYPTED_KEY.BASE64URL_IV.BASE64URL_CIPHERTEXT.BASE64URL_TAG

Send the Compact string directly. Do not wrap it in a JSON object, add JSON quotation marks, or Base64-encode the entire string again. The encrypted CEK is already the second segment; no custom encrypted-key HTTP header is used.

Encrypt and decrypt a response

ELECQ response processing

  1. Authenticate the request and check the operation's scopes and permitted data range.
  2. Build the complete business response JSON for one page.
  3. Generate a fresh CEK and IV. Encrypt the UTF-8 JSON with A256GCM and authenticate the protected header as specified by JWE.
  4. Encrypt the CEK with the client's registered recipient public key using RSA-OAEP-256.
  5. Return the five-segment Compact body with the response headers shown above.

Recipient processing

  1. Check the HTTP status and Content-Type before attempting decryption. Handle API-generated errors using the operation's JSON error contract. Gateway errors may have a different body or Content-Type.
  2. Parse the JWE Compact string. Accept only alg=RSA-OAEP-256 and enc=A256GCM, with no compression.
  3. Resolve kid against your own trusted private-key configuration. Do not use the header to fetch an arbitrary key or silently select a different key.
  4. Use the selected RSA private key to decrypt encrypted_key and recover the CEK. Ensure both OAEP and MGF1 use SHA-256.
  5. Decrypt the ciphertext and verify the authentication tag using the CEK, IV, and encoded protected header. Do not consume plaintext unless verification succeeds.
  6. Decode the verified plaintext as UTF-8 and parse the JSON. Preserve string values, including leading zeroes in credentials and identifiers.
  7. For paginated responses, persist the page successfully before saving its cursor and requesting the next page.

Pagination and retries

Each page is encrypted independently. A retry that generates a new response uses a new CEK and IV, so identical business data can produce different ciphertext. Do not compare encrypted strings to identify duplicate pages.

Follow the endpoint's pagination contract. Pagination metadata becomes available after successful decryption. Process records idempotently using their identifiers, and save the next cursor only after the page has been processed successfully.

Key rotation

Generate a replacement RSA key pair and provide ELECQ with the new PEM public key file and the same client ID. Coordinate the activation time with ELECQ, obtain the new key identifier (kid), and configure the matching private key in your backend before the switch.

After activation, requests that select the new recipient key use it without a service restart or a new access token. Keep using an unexpired token; valid pagination cursors also remain usable. An in-flight response may still use the previous key. For an uninterrupted transition, support both key IDs and select the matching private key using the response's kid. Alternatively, pause requests and finish processing outstanding responses before switching.

Retain the previous private key for as long as you need to decrypt responses encrypted to it, including stored responses or responses still being processed. The new private key cannot decrypt responses encrypted to the previous key.

Error handling

API-generated errors use the operation's documented JSON error format, without device credentials. Missing or invalid recipient-key configuration returns 403; a known encryption failure returns 503. Unexpected internal errors return 500. The service never falls back to plaintext business data. Gateway-generated errors, including rate limits, may have a different format. Check status and Content-Type first.

SituationWhat to check or do
Non-success HTTP responseHandle the HTTP status and Content-Type. Follow the API JSON error contract when applicable; do not attempt to decrypt an OAuth, API, or gateway error as JWE.
Plaintext success from an endpoint requiring this profileReject the unexpected response and investigate the content type and endpoint configuration.
Unknown kidCheck key registration, activation, and retained private keys. Do not guess a key.
RSA decryption failureCheck that the private key matches kid and that OAEP and MGF1 both use SHA-256.
Authentication tag verification failureReject the response. Check for truncation, modified segments, or an incompatible JOSE implementation; do not consume partial plaintext.
A different ciphertext on retryExpected when a new response is generated. Use decrypted record identifiers and pagination state for duplicate handling.

Security boundaries

Keep HTTPS and OAuth2 authentication enabled. Do not log private keys, CEKs, access tokens, or decrypted device credentials. Enforce the configured algorithms and reject invalid authentication tags.

Public-key JWE provides confidentiality and authenticated encryption. It is not an ELECQ digital signature and does not by itself prevent replay. If your integration requires offline verification of the sender or replay protection, agree those additional requirements separately.

Related documentation


Did this page help you?