BinCode/utils/security.js
2025-01-17 15:05:21 -05:00

22 lines
437 B
JavaScript

const crypto = require('crypto');
const generateSecureId = (length = 21) => {
return crypto
.randomBytes(Math.ceil(length * 3 / 4))
.toString('base64')
.slice(0, length)
.replace(/\+/g, '-')
.replace(/\//g, '_');
};
const sanitizeInput = (input) => {
if (typeof input !== 'string') return input;
return input
.replace(/[<>]/g, '')
.trim();
};
module.exports = {
generateSecureId,
sanitizeInput
};