import crypto from 'crypto' export const encrypt = (string = '', key = 'AnyKey', buffer = '1234567891011121') => { if (typeof string !== 'string') throw new Error('String must be a string') if (typeof key !== 'string') throw new Error('Key must be a string') if (buffer?.length !== 16) throw new Error('Buffer must be 16 characters long') const cipher = crypto.createCipheriv('aes-256-ctr', key, buffer); const encrypted = Buffer.concat([cipher.update(string), cipher.final()]); return encrypted.toString('hex') } export const decrypt = (string = '', key = 'AnyKey', buffer = '1234567891011121') => { if (typeof string !== 'string') throw new Error('String must be a string') if (typeof key !== 'string') throw new Error('Key must be a string') if (buffer?.length !== 16) throw new Error('Buffer must be 16 characters long') const decipher = crypto.createDecipheriv('aes-256-ctr', key, buffer); const decrpyted = Buffer.concat([decipher.update(Buffer.from(string, 'hex')), decipher.final()]); return decrpyted.toString(); } export const randomString = (length = 32) => { return Array(length).fill('').map(() => crypto.randomInt(0,9)).join('') } export default { encrypt, decrypt, randomString }