Cryptography
Post-quantum cryptographic primitives, key management, and secure storage for building security-first applications.
Supported Algorithms
| Category | Algorithms | Use Case |
|---|---|---|
| Signatures | Ed25519, secp256k1, Dilithium | Digital signatures |
| Key Exchange | X25519, Kyber | Secure key agreement |
| Encryption | AES-256-GCM, ChaCha20-Poly1305 | Data encryption |
| Hashing | Blake3, SHA-256, SHA-3 | Data integrity |
| BLS | BLS12-381 | Aggregate signatures |
Key Generation
import { Tenzro } from '@tenzro/cloud';const client = new Tenzro({apiKey: process.env.TENZRO_API_KEY,});// Create AES key for symmetric encryptionconst aesKey = await client.security.createKey({type: 'AES',size: 256,name: 'my-encryption-key',});// Create RSA keypairconst rsaKey = await client.security.createKey({type: 'RSA',size: 2048,name: 'my-rsa-key',});// Create EC keypairconst ecKey = await client.security.createKey({type: 'EC',curve: 'P-256',name: 'my-ec-key',});// Create post-quantum KYBER keypairconst kyberKey = await client.security.createKey({type: 'KYBER',variant: 'KYBER768', // or KYBER1024name: 'my-pq-key',});
Digital Signatures
// Sign data with RSA or EC keyconst signature = await client.security.sign({keyId: rsaKey.id,data: messageBytes,algorithm: 'RSA-PSS',});// Verify signatureconst isValid = await client.security.verify({keyId: rsaKey.id,data: messageBytes,signature,algorithm: 'RSA-PSS',});console.log('Valid:', isValid); // true
Encryption & Decryption
// Symmetric encryption (AES-256-GCM)const encrypted = await client.security.encrypt({keyId: aesKey.id,plaintext: 'sensitive data',algorithm: 'AES-GCM',});console.log('Ciphertext:', encrypted.ciphertext);console.log('IV:', encrypted.iv);// Decryptconst decrypted = await client.security.decrypt({keyId: aesKey.id,ciphertext: encrypted.ciphertext,iv: encrypted.iv,algorithm: 'AES-GCM',});console.log('Plaintext:', decrypted.plaintext);
Hashing
// Hash data with SHA-256const hash = await client.security.hash({data: 'input data',algorithm: 'SHA-256',});console.log('Hash:', hash.digest);// HMAC (keyed hash)const hmac = await client.security.hmac({keyId: aesKey.id,data: 'message to authenticate',algorithm: 'HMAC-SHA256',});console.log('HMAC:', hmac.signature);
Key Derivation
// Derive key from password using PBKDF2const derivedKey = await client.security.deriveKey({password: 'user-password',salt: 'random-salt',algorithm: 'PBKDF2',iterations: 100000,keyLength: 256,});console.log('Derived Key:', derivedKey.key);
Post-Quantum Cryptography
Future-proof your security with quantum-resistant algorithms using KYBER Key Encapsulation Mechanism (KEM):
// Create post-quantum KYBER keypairconst kyberKey = await client.security.createKey({type: 'KYBER',variant: 'KYBER768', // or KYBER1024 for higher securityname: 'pq-key',});// Encapsulation: Generate shared secret and ciphertextconst encapsulated = await client.security.encapsulate({keyId: kyberKey.id,});console.log('Ciphertext:', encapsulated.ciphertext);console.log('Shared Secret:', encapsulated.sharedSecret);// Decapsulation: Recover shared secret from ciphertextconst decapsulated = await client.security.decapsulate({keyId: kyberKey.id,ciphertext: encapsulated.ciphertext,});console.log('Recovered Secret:', decapsulated.sharedSecret);// Use shared secret for symmetric encryptionconst encrypted = await client.security.encrypt({plaintext: 'quantum-safe message',key: decapsulated.sharedSecret,algorithm: 'AES-GCM',});
Key Exchange with Post-Quantum KEM
// Alice creates a KYBER keyconst aliceKey = await client.security.createKey({type: 'KYBER',variant: 'KYBER768',name: 'alice-key',});// Bob encapsulates with Alice's public keyconst bobEncaps = await client.security.encapsulate({keyId: aliceKey.id,});// Bob sends ciphertext to Alice// Alice decapsulates with her private keyconst aliceDecaps = await client.security.decapsulate({keyId: aliceKey.id,ciphertext: bobEncaps.ciphertext,});// Both parties now share the same secretconsole.log('Secrets match:',bobEncaps.sharedSecret === aliceDecaps.sharedSecret);
Random Number Generation
// Generate cryptographically secure random bytesconst random = await client.security.randomBytes({length: 32,});console.log('Random bytes:', random.bytes);
Key Management
// List all keysconst keys = await client.security.listKeys();for (const key of keys.items) {console.log(`Key: ${key.name} (Type: ${key.type}, ID: ${key.id})`);}// Get key detailsconst keyInfo = await client.security.getKey(aesKey.id);console.log('Key metadata:', keyInfo.metadata);console.log('Created at:', keyInfo.createdAt);// Update key metadataawait client.security.updateKey(aesKey.id, {metadata: { purpose: 'database encryption' },});// Delete a keyawait client.security.deleteKey(aesKey.id);
Best Practices
- Use AES-256-GCM for symmetric encryption (authenticated)
- Use RSA-PSS or EC (P-256) for digital signatures
- Use KYBER for post-quantum key exchange
- Use SHA-256 or SHA-512 for cryptographic hashing
- Store keys securely - never expose private keys
- Rotate encryption keys regularly
- Use secure enclaves for hardware-protected keys
- Enable key versioning for compliance requirements