Generates a random 32-byte (256-bit) key for creating an encrypted index with an SDK-supplied key.
Parameters
Returns
bytes: 32 bytes from Python’s secrets.token_bytes(32), which reads the operating system’s cryptographic random source.
Saving the key
With save=True:
- If
~/.cyborgdb/index_key exists and holds exactly 32 bytes, that key is returned and no new key is generated.
- Otherwise a new key is generated, written to that file, and returned.
The file is not encrypted, and the SDK logs a warning each time it’s used. Use save=True for local development only; in production, store keys in a secrets manager or use a KMS-backed index. See Managing Encryption Keys.
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.
Example Usage