@@ -111,61 +111,6 @@ for await (const item of s5.fs.list("home/documents")) {
111111}
112112```
113113
114- ## Encryption
115-
116- Enhanced S5.js includes ** built-in encryption** using XChaCha20-Poly1305, providing both confidentiality and integrity for sensitive data.
117-
118- ### Basic Encryption
119-
120- ``` typescript
121- // Auto-generate encryption key
122- await s5 .fs .put (" home/secrets/credentials.json" , sensitiveData , {
123- encryption: {
124- algorithm: " xchacha20-poly1305" ,
125- },
126- });
127-
128- // Retrieve and decrypt automatically
129- const data = await s5 .fs .get (" home/secrets/credentials.json" );
130- console .log (data ); // Original decrypted data
131- ```
132-
133- ### User-Provided Encryption Keys
134-
135- ``` typescript
136- // Use your own 32-byte encryption key
137- const myKey = new Uint8Array (32 ); // Your secure key
138- crypto .getRandomValues (myKey );
139-
140- await s5 .fs .put (" home/private/document.txt" , " Secret content" , {
141- encryption: {
142- algorithm: " xchacha20-poly1305" ,
143- key: myKey , // Use specific key
144- },
145- });
146-
147- // Decryption uses key from metadata automatically
148- const content = await s5 .fs .get (" home/private/document.txt" );
149- ```
150-
151- ### Features
152-
153- - ** Algorithm** : XChaCha20-Poly1305 (AEAD cipher)
154- - ** Key Size** : 256-bit (32 bytes)
155- - ** Chunk-based** : Large files encrypted in 256 KiB chunks
156- - ** Transparent** : Automatic encryption/decryption
157- - ** Secure** : Each chunk uses unique nonce
158-
159- ### Security Considerations
160-
161- ⚠️ ** Important** : Encryption keys are stored in directory metadata. Anyone with directory read access can decrypt files. This design provides:
162-
163- - ✅ Convenience: No separate key management needed
164- - ✅ Automatic decryption with directory access
165- - ⚠️ Access control: Secure your directory access credentials
166-
167- For complete encryption documentation, examples, and security best practices, see the [ Encryption section in API.md] ( ./docs/API.md#encryption ) .
168-
169114### Advanced Usage
170115
171116``` typescript
@@ -310,6 +255,61 @@ Monitor bundle sizes with:
310255node scripts/analyze-bundle.js
311256```
312257
258+ ## Encryption
259+
260+ Enhanced S5.js includes ** built-in encryption** using XChaCha20-Poly1305, providing both confidentiality and integrity for sensitive data.
261+
262+ ### Basic Encryption
263+
264+ ``` typescript
265+ // Auto-generate encryption key
266+ await s5 .fs .put (" home/secrets/credentials.json" , sensitiveData , {
267+ encryption: {
268+ algorithm: " xchacha20-poly1305" ,
269+ },
270+ });
271+
272+ // Retrieve and decrypt automatically
273+ const data = await s5 .fs .get (" home/secrets/credentials.json" );
274+ console .log (data ); // Original decrypted data
275+ ```
276+
277+ ### User-Provided Encryption Keys
278+
279+ ``` typescript
280+ // Use your own 32-byte encryption key
281+ const myKey = new Uint8Array (32 ); // Your secure key
282+ crypto .getRandomValues (myKey );
283+
284+ await s5 .fs .put (" home/private/document.txt" , " Secret content" , {
285+ encryption: {
286+ algorithm: " xchacha20-poly1305" ,
287+ key: myKey , // Use specific key
288+ },
289+ });
290+
291+ // Decryption uses key from metadata automatically
292+ const content = await s5 .fs .get (" home/private/document.txt" );
293+ ```
294+
295+ ### Features
296+
297+ - ** Algorithm** : XChaCha20-Poly1305 (AEAD cipher)
298+ - ** Key Size** : 256-bit (32 bytes)
299+ - ** Chunk-based** : Large files encrypted in 256 KiB chunks
300+ - ** Transparent** : Automatic encryption/decryption
301+ - ** Secure** : Each chunk uses unique nonce
302+
303+ ### Security Considerations
304+
305+ ⚠️ ** Important** : Encryption keys are stored in directory metadata. Anyone with directory read access can decrypt files. This design provides:
306+
307+ - ✅ Convenience: No separate key management needed
308+ - ✅ Automatic decryption with directory access
309+ - ⚠️ Access control: Secure your directory access credentials
310+
311+ For complete encryption documentation, examples, and security best practices, see the [ Encryption section in API.md] ( ./docs/API.md#encryption ) .
312+
313313## Documentation
314314
315315- [ API Documentation] ( ./docs/API.md ) - Complete API reference with examples
0 commit comments