@imgproxy/imgproxy-node
Version:
Official node url-builder lib for imgproxy - fast and secure standalone server for resizing and converting remote images
17 lines (16 loc) • 843 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = __importDefault(require("crypto"));
const bufferToBase64_js_1 = __importDefault(require("./bufferToBase64.js"));
const getEncryptedUrl = (url, pair) => {
const bufferKey = Buffer.from(pair.key, "hex");
const iv = Buffer.from(pair.iv, "hex");
const data = Buffer.from(url).toString("binary");
const cipher = crypto_1.default.createCipheriv("aes-256-cbc", bufferKey, iv);
const encrypted = Buffer.from(cipher.update(data, "utf8", "binary") + cipher.final("binary"), "binary");
return (0, bufferToBase64_js_1.default)(Buffer.concat([iv, encrypted]));
};
exports.default = getEncryptedUrl;