Encryption Services
The EncryptionService provides high-level data protection utilities for persistent storage. It handles complex cryptographic workflows like salt management, key derivation, and binary sanitization automatically.
Core Encryption
Encrypt any serializable data into a versioned, secure JSON package. By default, XyPriss uses AES-256-GCM with 100,000 PBKDF2 iterations for key derivation.
import { EncryptionService } from "xypriss-security";
// Encrypt an object
const secretPackage = await EncryptionService.encrypt(
{ pin: 1234, token: "active" },
"master-passphrase"
);
// Decrypt back to object
const originalData = await EncryptionService.decrypt(secretPackage, "master-passphrase");Advanced Options
Quantum-Safe Mode
Enabling quantumSafe forces the use of ChaCha20-Poly1305, which offers better resistance to certain theoretical quantum cryptanalysis vectors.
await EncryptionService.encrypt(data, key, { quantumSafe: true });Integrity Checks
Verify the format and version of an encrypted package without needing the master key.
const info = EncryptionService.getMetadata(secretPackage);
console.log(info.algorithm); // aes-256-gcmAPI Reference
generateSessionKey()
Generates a secure 256-bit session key in hexadecimal format.
verifyIntegrity(package)
Checks if the package format is valid and readable by XyPriss.
Encoding and general cryptographic helpers.
