Security Utilities
The Utilities module provides foundational helpers for encoding, decoding, byte manipulation, and key derivation. These functions ensure consistency and performance across all cryptographic operations.
Encoding Utilities
Convert data between binary buffers and various string formats with zero-allocation efficiency.
Buffer to String
bufferToHex(buffer)bufferToBase64(buffer, urlSafe?)bufferToString(buffer)(UTF-8)
String to Buffer
hexToBuffer(hexString)base64ToBuffer(base64String, urlSafe?)stringToBuffer(utf8String)
Unified Utils Interface
The Utils object provides a consolidated entry point for the most commonly used operations.
typescript
import { Utils } from "xypriss-security";
// Quick Hash
const hex = Utils.hash("sensitive-data");
// Secure Random Bytes
const bytes = Utils.getRandomBytes(16);
// Fast string-to-string encryption (native bridge)
const encrypted = await Utils.encrypt("message", "passphrase");Key Derivation (KDF)
Derive cryptographically strong keys from weak secrets using Argon2id, PBKDF2, or HKDF.
typescript
import { deriveKey } from "xypriss-security";
const key = await deriveKey("my-secret", {
algorithm: "pbkdf2",
iterations: 310000,
keyLength: 32,
salt: "unique-salt-string",
});Byte Precision
UTF-8
Handling Multi-byte Characters
Standard .length counts characters. XyPriss utilities count actual bytes, which is critical for AES-256 (32 bytes) or Ed25519 (32 bytes) key material validation.
typescript
getByteLength("you好"); // 8 bytes (好 = 3 bytes)Enterprise Suite (XEMS)
Proceed to the high-performance encrypted memory store documentation.
