|
LibJWT 3.4.0
The C JSON Web Token Library +JWK +JWKS
|
Decrypt and authenticate JWE tokens. More...
Typedefs | |
| typedef struct jwe_checker | jwe_checker_t |
| Opaque JWE Checker (decryption) object. | |
Functions | |
| jwe_checker_t * | jwe_checker_new (void) |
| Create a new JWE checker instance. | |
| void | jwe_checker_free (jwe_checker_t *checker) |
| Free a previously created JWE checker object. | |
| int | jwe_checker_error (const jwe_checker_t *checker) |
| Check error state of a JWE checker object. | |
| const char * | jwe_checker_error_msg (const jwe_checker_t *checker) |
| Get the error message contained in a JWE checker object. | |
| void | jwe_checker_error_clear (jwe_checker_t *checker) |
| Clear error state in a JWE checker object. | |
| int | jwe_checker_setkey (jwe_checker_t *checker, jwe_key_alg_t alg, jwe_enc_t enc, const jwk_item_t *key) |
| Set the key and algorithms for a JWE checker. | |
| unsigned char * | jwe_checker_decrypt (jwe_checker_t *checker, const char *token, size_t *plaintext_len) |
| Decrypt and authenticate a Compact Serialization JWE. | |
| unsigned char * | jwe_checker_decrypt_all (jwe_checker_t *checker, const char *token, size_t *plaintext_len) |
| Decrypt and authenticate a JWE in any serialization. | |
| const unsigned char * | jwe_checker_get_aad (const jwe_checker_t *checker, size_t *aad_len) |
| Get the JWE AAD recovered from a JSON-serialized token. | |
Decrypt and authenticate JWE tokens.
Consuming a JWE token mirrors the JWS checker: create a jwe_checker_t, configure it with the key and the expected algorithms, then decrypt and authenticate tokens.
| typedef struct jwe_checker jwe_checker_t |
Opaque JWE Checker (decryption) object.
| unsigned char * jwe_checker_decrypt | ( | jwe_checker_t * | checker, |
| const char * | token, | ||
| size_t * | plaintext_len ) |
Decrypt and authenticate a Compact Serialization JWE.
Parses the five-part token, recovers the CEK using the configured key and algorithms (jwe_checker_setkey), and verifies the authentication tag.
| checker | Pointer to a JWE checker object |
| token | A nil-terminated compact JWE string |
| plaintext_len | If non-NULL, set to the length of the returned plaintext on success |
plaintext_len gives the true length. | unsigned char * jwe_checker_decrypt_all | ( | jwe_checker_t * | checker, |
| const char * | token, | ||
| size_t * | plaintext_len ) |
Decrypt and authenticate a JWE in any serialization.
Like jwe_checker_decrypt, but auto-detects the serialization: a token beginning with { is parsed as a JSON Serialization (Flattened or General), otherwise as the Compact Serialization. For a General JWE the checker selects the recipient matching its configured key and algorithm.
| checker | Pointer to a JWE checker object |
| token | A nil-terminated JWE string (compact or JSON) |
| plaintext_len | If non-NULL, set to the length of the returned plaintext on success |
| int jwe_checker_error | ( | const jwe_checker_t * | checker | ) |
Check error state of a JWE checker object.
| checker | Pointer to a JWE checker object |
| void jwe_checker_error_clear | ( | jwe_checker_t * | checker | ) |
Clear error state in a JWE checker object.
| checker | Pointer to a JWE checker object |
| const char * jwe_checker_error_msg | ( | const jwe_checker_t * | checker | ) |
Get the error message contained in a JWE checker object.
| checker | Pointer to a JWE checker object |
| void jwe_checker_free | ( | jwe_checker_t * | checker | ) |
Free a previously created JWE checker object.
| checker | Pointer to a JWE checker object |
| const unsigned char * jwe_checker_get_aad | ( | const jwe_checker_t * | checker, |
| size_t * | aad_len ) |
Get the JWE AAD recovered from a JSON-serialized token.
After a successful jwe_checker_decrypt_all on a JSON Serialization that carried an aad member, returns the authenticated application AAD octets. Returns NULL if the last token had no AAD member (or was compact). The returned buffer is owned by the checker and valid until the next decrypt or until the checker is freed.
| checker | Pointer to a JWE checker object |
| aad_len | If non-NULL, set to the length of the returned AAD in bytes |
| jwe_checker_t * jwe_checker_new | ( | void | ) |
Create a new JWE checker instance.
| int jwe_checker_setkey | ( | jwe_checker_t * | checker, |
| jwe_key_alg_t | alg, | ||
| jwe_enc_t | enc, | ||
| const jwk_item_t * | key ) |
Set the key and algorithms for a JWE checker.
| checker | Pointer to a JWE checker object |
| alg | The expected JWE key management algorithm ("alg" header) |
| enc | The expected JWE content encryption algorithm ("enc" header) |
| key | The key (a JWK) used to recover the CEK |