UNPKG

xypriss-security

Version:

Advanced High-Performance Security Framework. Military-grade encryption, post-quantum resilience, and fortified data structures.

77 lines 3.42 kB
"use strict"; /*************************************************************************** * XyPriss Security - Unified Utility Hub * * @author NEHONIX (Nehonix-Team - https://github.com/Nehonix-Team) * @license Nehonix Open Source License (NOSL) ****************************************************************************/ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.decrypt = exports.encrypt = exports.getRandomBytes = exports.hash = void 0; __exportStar(require("./encoding"), exports); const Hash_1 = require("../core/Hash"); const Random_1 = require("../core/Random"); const bridge_1 = require("../core/bridge"); /** * High-performance cryptographic hashing utility. * Leverages the Go-backed core engine for extreme throughput and security. * * @param data - The string or byte array payload to hash. * @param options - Configuration options for the hashing algorithm. * @returns The resulting cryptographic hash in hex format. * @example * const hash = Utils.hash("sensitive data"); */ const hash = (data, options) => Hash_1.Hash.create(data, options); exports.hash = hash; /** * Generates cryptographically secure random bytes. * Utilizing Go's native `crypto/rand` module, it ensures true randomness * suitable for key generation, salts, and nonces. * * @param length - The number of bytes to generate. * @returns A specialized object containing the bytes and utility methods. * @example * const salt = Utils.getRandomBytes(16) */ const getRandomBytes = (length) => { return Random_1.Random.getRandomBytes(length); }; exports.getRandomBytes = getRandomBytes; /** * Military-grade string encryption utilizing AES-256-GCM or ChaCha20-Poly1305. * Designed for maximum performance with atomic Go FFI calls. * * @param data - The plaintext string to encrypt. * @param key - The secret key used for encryption (hex string). * @param algo - The target algorithm ("aes" or "chacha20"). * @returns Encrypted payload as `nonce:tag:ciphertext` hex string. * @throws {Error} If key size is invalid or encryption fails. */ const encrypt = (data, key, algo = "aes") => bridge_1.Bridge.encrypt(data, key, algo); exports.encrypt = encrypt; /** * High-speed string decryption utilizing AES-256-GCM or ChaCha20-Poly1305. * * @param encrypted - The encrypted payload in hex format. * @param key - The secret key used for decryption (hex string). * @param algo - The target algorithm ("aes" or "chacha20"). * @returns The original plaintext string. * @throws {Error} If authentication fails or format is corrupted. */ const decrypt = (encrypted, key, algo = "aes") => bridge_1.Bridge.decrypt(encrypted, key, algo); exports.decrypt = decrypt; //# sourceMappingURL=index.js.map