import {createCipheriv, randomBytes, scrypt, createDecipheriv} from 'crypto'
import {promisify} from 'util'
const APP_KEY= 'edededede generate a key';
async function encrypt(text: string){
const iv = randomBytes(16)
const key = await promisify(scrypt)(APP_KEY, 'salt', 32) as Buffer
const cipher = createCipheriv('aes-256-cbc', key, iv);
const encrypted = Buffer.concat([
cipher.update(text),
cipher.final()
]).toString('hex')
return Buffer.from(JSON.stringify({
encrypted,
iv: iv.toString('hex')
})).toString('base64')
}