UNPKG

cloakx

Version:

Cloakx is a secure, lightweight CLI tool to manage your development secrets locally — no cloud, no hassle. Store, retrieve, and manage secrets across projects with encryption and ease. 🔐 Perfect for solo devs, indie hackers, and teams who value speed, si

27 lines (26 loc) 1.21 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.encrypt = encrypt; exports.decrypt = decrypt; const crypto_1 = __importDefault(require("crypto")); const algorithm = 'aes-256-cbc'; const salt = 'cloak_salt'; function encrypt(text, password) { const key = crypto_1.default.scryptSync(password, salt, 32); const iv = crypto_1.default.randomBytes(16); const cipher = crypto_1.default.createCipheriv(algorithm, key, iv); const encrypted = Buffer.concat([cipher.update(text, 'utf8'), cipher.final()]); return `${iv.toString('hex')}:${encrypted.toString('hex')}`; } function decrypt(data, password) { const [ivHex, encryptedHex] = data.split(':'); const key = crypto_1.default.scryptSync(password, salt, 32); const iv = Buffer.from(ivHex, 'hex'); const encrypted = Buffer.from(encryptedHex, 'hex'); const decipher = crypto_1.default.createDecipheriv(algorithm, key, iv); const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]); return decrypted.toString('utf8'); }