> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cyborg.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Key

Generates a random 32-byte (256-bit) key for creating an encrypted index with an SDK-supplied key.

```typescript theme={null}
static generateKey(): Uint8Array   // Client.generateKey()
generateKey(): Uint8Array          // client.generateKey()
```

The static and instance forms are identical; use the static form when you don't have a client yet.

### Returns

`Uint8Array`: 32 bytes from the runtime's Web Crypto `crypto.getRandomValues()`. This works the same on Node.js, browsers, and Edge runtimes, and throws if the runtime has no Web Crypto implementation.

Unlike the Python SDK, there is no option to save the key to a file.

<Warning>An index created with an SDK-supplied key can only be opened with that exact key. If the key is lost, the index's data can't be decrypted. Store it in a secrets manager, or use a KMS-backed index. See [Managing Encryption Keys](../../guides/advanced/managing-keys).</Warning>

### Example Usage

```typescript theme={null}
import { Client } from 'cyborgdb';

const client = new Client({ baseUrl: 'http://localhost:8000', apiKey: 'your-api-key' });

const indexKey = Client.generateKey();
console.log(indexKey.length);
// Output: 32

const index = await client.createIndex({ indexName: 'my-secure-index', indexKey });

// Keep the key somewhere safe, e.g. as hex in a secrets manager
const keyHex = Array.from(indexKey, (b) => b.toString(16).padStart(2, '0')).join('');
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.