Piekļūstiet sava seifa saturam programmatiski ar zero-knowledge šifrēšanu.
Zero-knowledge arhitektūra un kriptogrāfiskie standarti
Vairogs API izmanto zero-knowledge arhitektūru, kas nozīmē, ka serveris nekad neredz atšifrētus datus. Visa šifrēšana un atšifrēšana notiek klienta pusē.
Militārā līmeņa simetriskā šifrēšana ar autentifikāciju.
Moderna eliptisko līkņu kriptogrāfija atslēgu apmaiņai.
100,000 iterācijas atslēgu atvasināšanai.
Serveris nekad neredz atšifrētus datus.
┌─────────────────────────────────────────────────────────────────┐ │ VIENUMA ŠIFRĒŠANA │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ ┌─────────────┐ ┌─────────────────────┐ │ │ │ Plaintext │ │ Encrypted Item │ │ │ │ Data │ ──── AES-256-GCM ───> │ (encryptedData) │ │ │ └─────────────┘ └─────────────────────┘ │ │ │ │ │ │ │ │ │ │ v v │ │ ┌─────────────┐ ┌─────────────────────┐ │ │ │ Random DEK │ ──── NaCl Box ────> │ Key Slots │ │ │ │ (32 bytes) │ │ (encrypted DEK │ │ │ └─────────────┘ │ per recipient) │ │ │ └─────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────┘ ┌─────────────────────────────────────────────────────────────────┐ │ KEY SLOTS SISTĒMA │ ├─────────────────────────────────────────────────────────────────┤ │ │ │ Katram vienumam var būt vairāki "key slots": │ │ │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Slot: "main" │ │ Slot: "vgtk_a_" │ │ │ │ (Galvenais │ │ (MCP/API │ │ │ │ lietotājs) │ │ atslēga) │ │ │ └─────────────────┘ └─────────────────┘ │ │ │ │ │ │ v v │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ User PublicKey │ │ MCP PublicKey │ │ │ │ (asymmetric │ │ (derived from │ │ │ │ master key) │ │ vgtk_d_ key) │ │ │ └─────────────────┘ └─────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────────┘
Tag API v2 Parametri
Šīs konstantes jāizmanto, implementējot Tag API v2 atšifrēšanu.
// Atslēgu atvasināšana
const MCP_SALT = 'vairogs-mcp-key-derivation-v1'
const PBKDF2_ITERATIONS = 100000
const KEY_LENGTH = 32 // bytes
// AES-256-GCM parametri
const AES_KEY_LENGTH = 32 // 256 bits
const IV_LENGTH = 12 // 96 bits (GCM standarts)
const AUTH_TAG_LENGTH = 16 // 128 bits
// NaCl Box parametri
const NACL_NONCE_LENGTH = 24 // bytes
const NACL_PUBLIC_KEY_LENGTH = 32
const NACL_SECRET_KEY_LENGTH = 32
// Key Slot identifikatori
const MAIN_KEY_SLOT = 'main'
const MCP_KEY_PREFIX_LENGTH = 15 // Pirmie 15 simboli no access keyimport nacl from 'tweetnacl'
import crypto from 'crypto'
// Atvasina X25519 atslēgu pāri no Decryption Key
function deriveKeypair(decryptKey: string) {
// 1. PBKDF2 ar 100k iterācijām
const seed = crypto.pbkdf2Sync(
decryptKey, // vgtk_d_xxx atslēga
MCP_SALT, // 'vairogs-mcp-key-derivation-v1'
PBKDF2_ITERATIONS, // 100000
KEY_LENGTH, // 32
'sha256'
)
// 2. Ģenerē NaCl Box keypair no seed
const keypair = nacl.box.keyPair.fromSecretKey(new Uint8Array(seed))
return {
publicKey: keypair.publicKey, // Atbilst mcpPublicKey serverī
secretKey: keypair.secretKey // Izmanto atšifrēšanai
}
}Izmanto PBKDF2 + NaCl box.keyPair.fromSecretKey()
Meklē slot ar keyId = pirmie 15 simboli no Access Key (vgtk_a_xxxxxxx)
Izmanto encryptedDEK, nonce, senderPublicKey no slot un savu secretKey
Izmanto DEK un IV no vienuma, lai atšifrētu encryptedData
// Pilns atšifrēšanas piemērs
async function decryptItem(item: EncryptedItem, keypair: nacl.BoxKeyPair, accessKey: string) {
// 1. Atrast pareizo key slot
const mcpKeyPrefix = accessKey.substring(0, 15) // 'vgtk_a_xxxxxxx'
const keySlot = item.keySlots.find(s => s.keyId === mcpKeyPrefix)
if (!keySlot) throw new Error('Key slot not found')
// 2. Atšifrēt DEK ar NaCl box
const encryptedDEK = base64ToUint8Array(keySlot.encryptedDEK)
const nonce = base64ToUint8Array(keySlot.nonce)
const senderPublicKey = base64ToUint8Array(keySlot.senderPublicKey)
const dek = nacl.box.open(encryptedDEK, nonce, senderPublicKey, keypair.secretKey)
if (!dek) throw new Error('Failed to decrypt DEK')
// 3. Atšifrēt datus ar AES-GCM
const iv = base64ToUint8Array(item.iv)
const encryptedData = base64ToUint8Array(item.encryptedData)
const decipher = crypto.createDecipheriv('aes-256-gcm', Buffer.from(dek), iv)
const authTag = encryptedData.slice(-16) // Pēdējie 16 baiti
const ciphertext = encryptedData.slice(0, -16)
decipher.setAuthTag(authTag)
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()])
return JSON.parse(decrypted.toString('utf8'))
}Access Key ir paredzēta HTTP pieprasījumiem. Decrypt Key izmanto tikai lokāli.
Access Key serverī tiek salīdzināta ar bcrypt hash, nevis plaintext.
Katram vienumam tiek ģenerēts jauns 12-baitu IV, nodrošinot kriptogrāfisku drošību.
Glabājiet atslēgas šifrētā veidā vai izmantojiet secret management sistēmas (Vault, AWS Secrets Manager).
Regulāri izveidojiet jaunas API atslēgas un dzēsiet vecās. Ieteicams vismaz reizi 90 dienās.
| Mērķis | Algoritms | Parametri |
|---|---|---|
| Datu šifrēšana | AES-256-GCM | 256-bit key, 96-bit IV, 128-bit auth tag |
| Atslēgu apmaiņa | X25519 (NaCl box) | 256-bit keys, 192-bit nonce |
| Atslēgu atvasināšana | PBKDF2-SHA256 | 100,000 iterācijas, 32-byte output |
| API key hash | bcrypt | Cost factor 12 |