// import fp from 'fastify-plugin';
// import crypto from 'crypto';
// import { FastifyInstance, FastifyPluginAsync } from 'fastify';

// const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY as string; // Ensure this is 32 bytes for AES-256
// const IV_LENGTH = 16; // AES block size

// const cryptoPlugin: FastifyPluginAsync = async (fastify: FastifyInstance) => {
//     fastify.decorate('encrypt', (text: string): string => {
//         const iv = crypto.randomBytes(IV_LENGTH);
//         const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
//         let encrypted = cipher.update(text);
//         encrypted = Buffer.concat([encrypted, cipher.final()]);
//         return iv.toString('hex') + ':' + encrypted.toString('hex');
//     });

//     fastify.decorate('decrypt', (text: string): string => {
//         const textParts = text.split(':');
//         const iv = Buffer.from(textParts.shift()!, 'hex');
//         const encryptedText = Buffer.from(textParts.join(':'), 'hex');
//         const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
//         let decrypted = decipher.update(encryptedText);
//         decrypted = Buffer.concat([decrypted, decipher.final()]);
//         return decrypted.toString();
//     });
// };

// export default fp(cryptoPlugin, {
//     name: 'cryptoPlugin',
//     decorators: {
//         fastify: ['encrypt', 'decrypt'],
//     },
// });
