POST /operations

API reference for the generic operations endpoint

The /operations endpoint provides a generic interface for cryptographic operations with full pipeline processing.

Endpoint

POST /api/v1/operations

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer token with API key
Content-TypeYesMust be application/json
X-Request-IdNoClient-provided request ID for tracing

Body

{
  "operation": "encrypt",
  "payload": { ... }
}
FieldTypeRequiredDescription
operationstringYesOperation type (see below)
payloadanyYesOperation-specific payload

Supported Operations

OperationDescription
encryptEncrypt payload with symmetric or hybrid encryption
decryptDecrypt an encrypted payload
signCreate a digital signature
verifyVerify a digital signature
hashCompute a cryptographic hash

Example Request

curl -X POST https://api.4quays.com/api/v1/operations \
  -H "Authorization: Bearer sk_live_xxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "operation": "encrypt",
    "payload": {
      "data": {
        "transferId": "txn-12345",
        "amount": 5000
      },
      "algorithm": "AES-256-GCM",
      "keyId": "key_abc123"
    }
  }'

Response

Success (200 OK)

{
  "requestId": "req_abc123",
  "result": { ... },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Error Response

{
  "error": {
    "code": "AUTHENTICATION_FAILED",
    "message": "Invalid or expired API key"
  },
  "requestId": "req_abc123"
}

Operation: Encrypt

Encrypt data with a specified algorithm and key.

Request

{
  "operation": "encrypt",
  "payload": {
    "data": { ... },
    "algorithm": "AES-256-GCM",
    "keyId": "key_abc123"
  }
}
FieldTypeRequiredDescription
dataanyYesData to encrypt
algorithmstringYesEncryption algorithm
keyIdstringNoSpecific key to use (optional)

Response

{
  "requestId": "req_abc123",
  "result": {
    "ciphertext": "base64-encoded-ciphertext",
    "iv": "base64-encoded-iv",
    "tag": "base64-encoded-tag",
    "algorithm": "AES-256-GCM",
    "keyId": "key_abc123"
  },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Operation: Decrypt

Decrypt previously encrypted data.

Request

{
  "operation": "decrypt",
  "payload": {
    "ciphertext": "base64-encoded-ciphertext",
    "iv": "base64-encoded-iv",
    "tag": "base64-encoded-tag",
    "algorithm": "AES-256-GCM",
    "keyId": "key_abc123"
  }
}

Response

{
  "requestId": "req_abc123",
  "result": {
    "data": { ... }
  },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Operation: Sign

Create a digital signature for data.

Request

{
  "operation": "sign",
  "payload": {
    "data": { ... },
    "algorithm": "RSA-SHA256",
    "keyId": "key_signing_123"
  }
}

Response

{
  "requestId": "req_abc123",
  "result": {
    "signature": "base64-encoded-signature",
    "algorithm": "RSA-SHA256",
    "keyId": "key_signing_123"
  },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Operation: Verify

Verify a digital signature.

Request

{
  "operation": "verify",
  "payload": {
    "data": { ... },
    "signature": "base64-encoded-signature",
    "algorithm": "RSA-SHA256",
    "keyId": "key_signing_123"
  }
}

Response

{
  "requestId": "req_abc123",
  "result": {
    "valid": true
  },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Operation: Hash

Compute a cryptographic hash.

Request

{
  "operation": "hash",
  "payload": {
    "data": { ... },
    "algorithm": "SHA-256"
  }
}
AlgorithmDescription
SHA-256SHA-2 256-bit
SHA-384SHA-2 384-bit
SHA-512SHA-2 512-bit

Response

{
  "requestId": "req_abc123",
  "result": {
    "hash": "base64-encoded-hash",
    "algorithm": "SHA-256"
  },
  "timestamp": "2026-02-09T10:30:00.000Z"
}

Processing Pipeline

Every operation goes through:

  1. Request parsing — Validate JSON structure
  2. Authentication — Verify API key (bcrypt)
  3. Key revocation check — Ensure key is not revoked
  4. Policy enforcement — Check operation is allowed
  5. Crypto operation — Perform the operation
  6. Response transformation — Format the response
  7. Audit logging — Log to crypto_operations_audit

Audit Trail

All operations are logged:

FieldDescription
request_idUnique request identifier
application_idCalling application's service ID
operation_typeencrypt, decrypt, sign, verify, hash
payload_size_bytesSize of input payload
response_statusHTTP status code
response_time_msTotal processing time
error_messageError details if failed

When to Use /operations vs /protect

Use CaseEndpoint
Policy-driven encryption for external services/protect
Policy-driven decryption from external services/unprotect
Direct crypto operations with specific algorithms/operations
Internal data encryption/operations
Signature creation/verification/operations
Hash computation/operations

Best Practices

  1. Prefer /protect for external integrations — Policies provide abstraction
  2. Use /operations for internal crypto — Direct control when needed
  3. Always log request IDs — For debugging
  4. Handle errors appropriately — Different operations have different failure modes