# Ejemplos de JSON

Ambos *endpoints* (`/encrypt` y `/decrypt`)  usarán una estructura similar para enviar y recibir datos.

#### 1. Para la Operación Encriptar (`/files/encrypt`)

El *body* debe enviar los datos sin cifrar. Para datos binarios (como un archivo), a menudo se utiliza una representación en Base64 para encapsularlos de forma segura dentro del JSON.

| Campo      | Tipo     | Descripción                                                                                                            | Ejemplo de Valor                                                           |
| ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| `data`     | `string` | Los datos sin cifrar que se van a proteger. Si es un archivo, debe estar codificado en Base64.                         | `"VGhpcyBpcyBhIHRlc3QgZGF0YQo="` (Esto es "This is a test data" en Base64) |
| `key_id`   | `string` | Identificador de la clave (alias) que la API debe usar para realizar el cifrado (necesario para la gestión de claves). | `"USER_SECRET_KEY_123"`                                                    |
| `metadata` | `object` | (Opcional) Metadatos adicionales para identificar el archivo o su contenido.                                           | `{"file_name": "informe_Q3.pdf"}`                                          |

**Ejemplo JSON:**

```
{
  "data": "VGhpcyBpcyBhIHRlc3QgZGF0YQo=",
  "key_id": "USER_SECRET_KEY_123",
  "metadata": {
    "file_name": "informe_Q3.pdf",
    "user_id": "richard.abanto"
  }
}
```

#### 2. Para la Operación Desencriptar (`/files/decrypt`)

El *body* debe enviar los datos cifrados junto con la información auxiliar (como el *Initialization Vector* o IV y la *Authentication Tag* o TAG, si no están incrustados en los datos) para que AES-256-GCM pueda descifrarlos correctamente.

| Campo        | Tipo     | Descripción                                                                                                   | Ejemplo de Valor                         |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| `ciphertext` | `string` | Los datos cifrados que la API debe descifrar (codificados en Base64).                                         | `"Y3lwaGVydGV4dERhdGFoYmNjZGVmZ2hpbms="` |
| `key_id`     | `string` | Identificador de la clave (alias) utilizada originalmente para el cifrado.                                    | `"USER_SECRET_KEY_123"`                  |
| `iv`         | `string` | Initialization Vector (IV) usado durante el cifrado (codificado en Base64). Necesario para GCM.               | `"SXZEYXRhMTIzNDU2Nzg5MAo="`             |
| `tag`        | `string` | Authentication Tag (TAG) para verificar la integridad del mensaje (codificado en Base64). Necesario para GCM. | `"VGFnRGF0YUFESzEyMzQ1Ngo="`             |

Ejemplo JSON:

```
{
  "ciphertext": "Y3lwaGVydGV4dERhdGFoYmNjZGVmZ2hpbms=",
  "key_id": "USER_SECRET_KEY_123",
  "iv": "SXZEYXRhMTIzNDU2Nzg5MAo=",
  "tag": "VGFnRGF0YUFESzEyMzQ1Ngo="
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://keyfortress.gitbook.io/es-apigateway-aes256-gcm/ejemplos-de-json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
