🔑Key Generation
🔑 Managing Keys
The KeyGenerator is a crucial component for creating and managing the keys required by the system. It allows for the secure generation of key sets, with advanced options for metadata encryption and key sealing to protect sensitive keys at rest. Keys can be generated and managed through both a Command-Line Interface (CLI) and a Python SDK.
In addition, key sealing supports the use of a Key Encryption Key (KEK), making it easier to integrate with external Key Management Systems (KMS) for enhanced security. For users who prefer not to manage raw keys themselves, enVector also supports AWS-backed key storage using services such as Amazon S3 and AWS Secrets Manager, so long-term key management can be delegated to AWS instead of the application.
Generated Key Files
When you generate a key set, the following files are created in the specified directory (<key_path>/<key_id>/).
SecKey.json: The Secret Key. This is a private key used to decrypt encrypted vectors and derive the public keys. It must be kept confidential and secure at all times.EncKey.json: The Public Encryption Key. This key is used to encrypt vectors before they are sent to the system. It can be shared publicly.EvalKey.json: The Public Evaluation Key. This key enables the server to perform computations (like similarity searches) directly on encrypted data. It is sent to the server during theregister_keyprocess and is safe to share. By default, it supports vector dimensions up to 4096.MetadataKey.json: The AES Metadata Key. This key is used to encrypt and decrypt metadata associated with your data in the index. It is only generated ifmetadata_encryptionis enabled.
ls <key_path>/<key_id>
EncKey.json EvalKey.json SecKey.json MetadataKey.jsonKey Generation Configuration
These options control how the keys and their metadata are generated and secured.
metadata_encryption(boolean, default:true) When enabled, aMetadataKey.jsonis generated. All metadata stored in the index is then encrypted using this AES key before being written, providing an end-to-end security.seal_mode(string, default:none) If set toaes, this enables key sealing. Sealing encrypts theSecKey.jsonandMetadataKey.jsonfiles using a Key Encryption Key (KEK). The encrypted keys are saved asSecKey.jsonandMetadataKey.json, and the original unsealed key files are no longer used by the system. This provides strong protection for your most sensitive keys at rest.seal_pathorseal_key_stdin(string) This specifies the Key Encryption Key (KEK) used for sealing whenseal_modeisaes.seal_path: Provides the file path to the KEK.seal_key_stdin: Reads the KEK from standard input instead of a file. This is a more secure method for automated environments (e.g., CI/CD pipelines) as it avoids writing the KEK to disk.
Generating Keys
You can generate keys using either the CLI or the Python SDK.
Command-Line Interface (CLI)
The pyenvector-keygen utility is used for key generation and management from the command line.
Example: Generate and Seal Keys
This command generates a key set identified by ev-key inside the keys directory and seals the secret keys using a KEK from the aes.kek file.
Example: Supply KEK via Standard Input
For enhanced security, you can pipe the KEK directly to the command, avoiding the need for a file on disk.
Python SDK
The enVector SDK provides two convenient ways to generate keys programmatically.
Note: The Envector CLI supports AES-KEK–based sealing, but the Python SDK does not support AES-KEK–based sealing yet; in Python, only unsealed raw keys are currently supported.
1. Using the KeyGenerator Class For direct control over key generation, you can use the KeyGenerator class.
2. Using the ev.init() Helper Function The ev.init() function provides a streamlined way to initialize your client environment. It can automatically generate and register keys if they don't already exist, making it ideal for getting started quickly.
Key Generation with AWS Key Storage
With AWS key storage, key material is generated in memory and uploaded to AWS using the KeyManager or CLI with key_store="aws". The SDK takes care of mapping keys to the configured AWS resources:
EncKey.jsonandEvalKey.jsonare stored as objects in Amazon S3.SecKey.jsonandMetadataKey.jsonare stored as encrypted secrets in AWS Secrets Manager.
Before You Begin
To use AWS key storage, make sure:
The target AWS region and S3 bucket exist and are provided via
region nameandbucket name.AWS credentials are configured for an IAM principal that can create and read Secrets Manager secrets.
AWS Storage (CLI & Python)
For production environments, you may want to store keys in AWS instead of on the local filesystem.
CLI: Generate Keys and Store Them in AWS
You can configure the CLI to generate keys and upload them directly to AWS:
This command generates a key set in memory and uploads it to AWS, storing public keys as S3 objects and secret keys as encrypted Secrets Manager entries using the bucket and prefix configuration above.
While using the CLI with --key_store aws, keep the following in mind (mirrors the built-in guardrails of the pyenvector-keygen script):
--key_id,--region_name, and--bucket_nameare mandatory;--secret_prefixis optional and lets you namespace multiple key sets.AWS mode always generates keys in-memory (
generate_keys_stream) and therefore skips local output directories.Sealing is not supported in AWS mode. Make sure
--seal_mode noneand skip--seal_key_path/--seal_key_stdin, otherwise the CLI will raise an error.Other generation parameters like
--dim,--preset,--eval_mode, and--metadata_encryptionwork the same as local generation and are forwarded to the SDK before uploading viaKeyManager.
Python: Upload an Existing Key to AWS
If you already generated a key set (for example using KeyGenerator.generate_keys_stream() in a previous step), you can upload the resulting key_dict to AWS with KeyManager(key_store="aws"):
Last updated

