安全

用于保护 Astreus 代理中敏感数据的字段级加密

概述#

Astreus 内置了 AES-256-GCM 加密,用于保护存储在数据库中的敏感数据。该功能为对话、系统提示词、任务数据和知识库内容提供透明的字段级加密。

快速设置#

1. 生成加密密钥#

bash
# Generate a cryptographically secure 256-bit key
openssl rand -hex 32

2. 配置环境#

bash
# Enable encryption
ENCRYPTION_ENABLED=true

# Your secure master key (keep this secret!)
ENCRYPTION_MASTER_KEY=your-256-bit-encryption-key-here

# Optional: specify algorithm (default: aes-256-gcm)
ENCRYPTION_ALGORITHM=aes-256-gcm

3. 正常使用#

javascript
import { Agent } from '@astreus-ai/astreus';

// Create agent with sensitive system prompt
const agent = await Agent.create({
  name: 'SecureAgent',
  systemPrompt: 'Your confidential business logic here', // ← Automatically encrypted
  memory: true,
  knowledge: true
});

// All interactions automatically encrypted
const response = await agent.ask('Sensitive question here');

// Knowledge uploads automatically encrypted
await agent.knowledge.addDocument(
  'Confidential Document', 
  'Sensitive content here' // ← Automatically encrypted
);

密钥管理#

主密钥要求#

  • 最小长度:32 个字符(256 位)
  • 生成方式:使用密码学安全的随机数生成器
  • 存储方式:安全地存储在代码库之外
  • 轮换策略:规划定期的密钥轮换