---
name: "jose_jwk"
section: "3"
platform: "linux"
package: "jose"
version: "15-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/jose_jwk"
---

# jose\_jwk(3)

JSON Web Keys (RFC 7517)

## NAME

jose\_jwk - JSON Web Keys (RFC 7517)

## SYNOPSIS

### Functions

bool **jose\_jwk\_gen** (jose\_cfg\_t \*cfg, json\_t \*jwk)\
 Generates a new JWK.  bool **jose\_jwk\_pub** (jose\_cfg\_t \*cfg, json\_t \*jwk)\
 Removes all private key material from a JWK.  bool **jose\_jwk\_prm** (jose\_cfg\_t \*cfg, const json\_t \*jwk, bool req, const char \*op)\
 Determines if an operation is permitted for a JWK.  json\_t \* **jose\_jwk\_thp** (jose\_cfg\_t \*cfg, const json\_t \*jwk, const char \*alg)\
 Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string.  size\_t **jose\_jwk\_thp\_buf** (jose\_cfg\_t \*cfg, const json\_t \*jwk, const char \*alg, uint8\_t \*thp, size\_t len)\
 Calculates the thumbprint of a JWK.  json\_t \* **jose\_jwk\_exc** (jose\_cfg\_t \*cfg, const json\_t \*prv, const json\_t \*pub)\
 Perform a key exchange.

## Detailed Description

JSON Web Keys (RFC 7517)

A JSON Web Key (JWS) is a standard data format for expresing cryptographic keys in JSON.

**See also:**

https://tools.ietf.org/html/rfc7517

https://tools.ietf.org/html/rfc7638

## Function Documentation

### bool jose\_jwk\_gen (jose\_cfg\_t \* cfg, json\_t \* jwk)

Generates a new JWK. The JWK is generated using hints from the input in exactly the same format as you would find in the output. For example, the most common way to generate a key is to specify the algorithm you'd like to use the key with. For example (error handling omitted):

```
json_t *gen(void) {
    json_auto_t *jwk = json_pack("{s:s}", "alg", "ES256");
    jose_jwk_gen(NULL, jwk);
    return json_incref(jwk);
}
```

This method is preferred because other metadata can be inferred from the algorithm name, such as the key usage. Additionally, the algorithm metadata can be used to automatically generate correct headers when creating signatures (JWS) or encryptions (JWE). Thus, you should always default to creating keys by their algorithm usage.

However, should your requirements differ, you can also generate a key using raw parameters (again, error handling omitted):

```
json_t *gen(void) {
    json_auto_t *jwk = json_pack("{s:s,s:s}", "kty", "EC", "crv", "P-256");
    jose_jwk_gen(NULL, jwk);
    return json_incref(jwk);
}
json_t *gen(void) {
    json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "RSA", "bits", 2048);
    jose_jwk_gen(NULL, jwk);
    return json_incref(jwk);
}
json_t *gen(void) {
    json_auto_t *jwk = json_pack("{s:s,s:i}", "kty", "oct", "bytes", 32);
    jose_jwk_gen(NULL, jwk);
    return json_incref(jwk);
}
```

In this case, 'bits' and 'bytes' will be removed from the final output.

**See also:**

https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms

**Parameters:**

*cfg* The configuration context (optional). \
 *jwk* The JWK to generate.

**Returns:**

On success, true. Otherwise, false.

### bool jose\_jwk\_pub (jose\_cfg\_t \* cfg, json\_t \* jwk)

Removes all private key material from a JWK. In addition, this function will remove any key operations from the `key_ops` JWK property (if present) that apply only to the private key.

This function should be used before exporting keys to third parties.

**Parameters:**

*cfg* The configuration context (optional). \
 *jwk* The JWK to remove private keys from.

**Returns:**

On success, true. Otherwise, false.

### bool jose\_jwk\_prm (jose\_cfg\_t \* cfg, const json\_t \* jwk, bool req, const char \* op)

Determines if an operation is permitted for a JWK. The operation to be confirmed (`op`) is always specified according to the syntax of the 'key\_ops' JWK property, even when the 'use' property is defined on the JWK.

This function has two modes of operation. If `req` is false, then JWKs which do not have any key use metadata will be approved for this operation. However, if `req` is true then this metadata will be required for approval.

**Parameters:**

*cfg* The configuration context (optional). \
 *jwk* The JWK from which to remove private keys. \
 *req* Whether JWK key use metadata is required or not. \
 *op* The opperation to seek approval for.

**Returns:**

When the JWK is approved, true. Otherwise, false.

### json\_t\* jose\_jwk\_thp (jose\_cfg\_t \* cfg, const json\_t \* jwk, const char \* alg)

Calculates the thumbprint of a JWK as a URL-safe Base64 encoded JSON string. This function is a thin wrapper around **jose\_jwk\_thp\_buf()**.

**See also:**

**jose\_jwk\_thp\_buf()**

**Parameters:**

*cfg* The configuration context (optional). \
 *jwk* The JWK to calculate the thumbprint for. \
 *alg* The hash algorithm to use.

**Returns:**

On success, a newly-allocated JSON string. Otherwise, NULL.

### size\_t jose\_jwk\_thp\_buf (jose\_cfg\_t \* cfg, const json\_t \* jwk, const char \* alg, uint8\_t \* thp, size\_t len)

Calculates the thumbprint of a JWK. This function calculates the thumbprint of a JWK according to the method defined by RFC 7638.

If `thp` is NULL, this function returns the size of the buffer required for the thumbprint output.

**See also:**

https://tools.ietf.org/html/rfc7638

**Parameters:**

*cfg* The configuration context (optional). \
 *jwk* The JWK to calculate the thumbprint for. \
 *alg* The hash algorithm to use. \
 *thp* The output hash buffer. \
 *len* The size of the output hash buffer.

**Returns:**

On success, the number of bytes written. Otherwise, SIZE\_MAX.

### json\_t\* jose\_jwk\_exc (jose\_cfg\_t \* cfg, const json\_t \* prv, const json\_t \* pub)

Perform a key exchange. The only currently implemented algorithm is ECDH.

**Parameters:**

*cfg* The configuration context (optional). \
 *prv* The private JWK. \
 *pub* The public JWK.

**Returns:**

On success, the JWK result of the key exchange. Otherwise, NULL.

## Author

Generated automatically by Doxygen for José from the source code.
