Encryption in JS

@Shoaib

2/2. decrypt.js

import {createCipheriv, randomBytes, scrypt, createDecipheriv} from 'crypto'
import {promisify} from 'util'

// You can generate an APP_KEY for your app
const APP_KEY= 'edededede generate a key';

async function decrypt(hash: string){
const decodedHash = Buffer.from(hash, 'base64')
const jsonHash = JSON.parse(decodedHash.toString())

const key = await promisify(scrypt)(APP_KEY, 'salt', 32) as Buffer
const decipher = createDecipheriv('aes-256-cbc', key, Buffer.from(jsonHash.iv, 'hex'))
return Buffer.concat([
decipher.update(Buffer.from(jsonHash.encrypted, 'hex')),
decipher.final()
]).toString()
}