You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The model encryption methods provide a higher-level interface that's particularly useful when working with ORMs or when you need to encrypt multiple fields in an object.
529
529
They automatically handle the mapping between your model's structure and the encrypted fields defined in your schema.
530
530
531
+
### Bulk operations
532
+
533
+
Protect.js provides direct access to ZeroKMS bulk operations through the `bulkEncrypt` and `bulkDecrypt` methods. These methods are ideal when you need maximum performance and want to handle the correlation between encrypted/decrypted values and your application data manually.
534
+
535
+
> [!TIP]
536
+
> The bulk operations provide the most direct interface to ZeroKMS's blazing fast bulk encryption and decryption capabilities. Each value gets a unique key while maintaining optimal performance through a single call to ZeroKMS.
537
+
538
+
#### Bulk encryption
539
+
540
+
Use the `bulkEncrypt` method to encrypt multiple plaintext values at once:
541
+
542
+
```typescript
543
+
import { protectClient } from"./protect";
544
+
import { users } from"./protect/schema";
545
+
546
+
// Array of plaintext values with optional IDs for correlation
The `bulkDecrypt` method returns an array of objects with the following structure:
620
+
621
+
```typescript
622
+
[
623
+
{ id: "user1", data: "alice@example.com" },
624
+
{ id: "user2", data: "bob@example.com" },
625
+
{ id: "user3", data: "charlie@example.com" },
626
+
]
627
+
```
628
+
629
+
#### Response structure
630
+
631
+
The `bulkDecrypt` method returns a `Result` object that represents the overall operation status. When successful from an HTTP and execution perspective, the `data` field contains an array where each item can have one of two outcomes:
632
+
633
+
-**Success**: The item has a `data` field containing the decrypted plaintext
634
+
-**Failure**: The item has an `error` field containing a specific error message explaining why that particular decryption failed
> The underlying ZeroKMS response uses HTTP status code 207 (Multi-Status) to indicate that the bulk operation completed, but individual items within the batch may have succeeded or failed. This allows you to handle partial failures gracefully while still processing the successful decryptions.
649
+
650
+
You can handle mixed results by checking each item:
The bulk operations maintain the same security guarantees as individual operations - each value gets a unique key - while providing optimal performance through ZeroKMS's bulk processing capabilities.
753
+
531
754
### Store encrypted data in a database
532
755
533
756
Encrypted data can be stored in any database that supports JSONB, noting that searchable encryption is only supported in PostgreSQL at the moment.
0 commit comments