UNPKG

ffpr

Version:

Save editor for games of Final Fantasy Pixel Remaster

35 lines (34 loc) 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.decrypt = exports.encrypt = void 0; const crypto_1 = __importDefault(require("crypto")); const rijndael_js_1 = __importDefault(require("rijndael-js")); const password = 'TKX73OHHK1qMonoICbpVT0hIDGe7SkW0'; const salt = '71Ba2p0ULBGaE6oJ7TjCqwsls1jBKmRL'; const generator = crypto_1.default.pbkdf2Sync(password, salt, 10, 64, 'sha1'); const key = generator.slice(0, 32); const iv = generator.slice(32, 64); async function encrypt(input) { const cipher = new rijndael_js_1.default(key, 'cbc'); const blockSize = 32; const padLength = blockSize - (input.length % blockSize); const padded = Buffer.concat([input, Buffer.alloc(padLength)]); const encrypted = cipher.encrypt(padded, '256', iv); return Buffer.from(encrypted); } exports.encrypt = encrypt; async function decrypt(input) { const cipher = new rijndael_js_1.default(key, 'cbc'); const decrypted = Buffer.from(cipher.decrypt(input, '256', iv)); // remove extra zero padding let end = decrypted.length; while (end > 0 && decrypted[end - 1] == 0) { --end; } const unpadded = decrypted.slice(0, end + 1); return unpadded; } exports.decrypt = decrypt;